原来这样啊 2013-10-27 09:14
浏览 2593

杭州电子科技大学 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("%d\n\n", (in[j]%2) ? (((in[j]+1)/2)* in[j]) : ((in[j]/2)*(1+ in[j]))); //按照输入的n的值的顺序求值

}
}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?