一道简单的acm题,可是我老是通不过oj

一道简单的acm题,可是我老是通不过oj
Input
Inputcontains multiple test cases, and one case one line. Each case starts with aninteger N, and then N integers follow in the same line.

Output
For each testcase you should output the sum of N integers in one line, and with one line ofoutput for each line in input.
Sample Input
4 1 2 3 4
5 1 2 3 4 5


Sample Output
10
15
整股天师 1年前 已收到1个回答 举报

lingling77 幼苗

共回答了21个问题采纳率:90.5% 举报

#include

int main()
{
int n,x,sum;
while(scanf("%d",&n)!=EOF)
{
sum = 0;
while(n--)
{
scanf("%d",&x);
sum+=x;
}
printf("%d/n",sum);
}
return 0;
}学习一下输入输出就好,欢迎交流.

1年前 追问

1

整股天师 举报

oj也报错,还有你的换行应该是n

举报 lingling77

给个题目网址吧,我试一下。

整股天师 举报

http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=1&problemid=3006

举报 lingling77

#include

int main()
{
int n,x,sum;
while(scanf("%d",&n)!=EOF)
{
sum = 0;
while(n--)
{
scanf("%d",&x);
sum+=x;
}
printf("%dn",sum);
}
return 0;
}

这个是可以AC的,你试试哈。

可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.033 s. - webmaster@yulucn.com