问题描述
- 杭州电子科技大学 acm 第1001题
-
题目的输入要求是The input will consist of a series of integers n one integer per line.输出要求是For each case output SUM(n) in one line followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.我提交的答案总是Runtime Error(ACCESS_VIOLATION).我想知道我写的代码怎么改是正确的,谢了(下面是我的代码)我的想法是一次输入一些数,然后用数组存起来,然后求和后再按行输出。
include
define LEN 20
int main()
{int in[LEN];
int i = 0 ;
int j;
int n;
while(scanf(""%d""&n) != EOF)
{
in[i] = n;//用数组来存储每次输入的n的值
i++;}
for(j = 0; (j < i) && (in[j] < 65536); j++)//in[j]<65536防止最后的结果超过要求的有符号32位的值
{
printf(""%dnn"" (in[j]%2) ? (((in[j]+1)/2)* in[j]) : ((in[j]/2)*(1+ in[j]))); //按照输入的n的值的顺序求值
}
}
时间: 2024-08-18 02:47:56