落絮飞雁

顺流而下,把梦做完

【ACM】ACM steps 1.1.6

A+B for Input-Output Practice (VI)

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18437 Accepted Submission(s): 12465

Problem Description
Your task is to calculate the sum of some integers.

Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

Sample Input
4 1 2 3 4
5 1 2 3 4 5

Sample Output
10
15
参考题解:

#include
int main()
{
int n,i,sum,t;
sum=0;
while(scanf(“%d”,&n)!=EOF)
{
for(i=0;i

这道题纠结了好久……一开始的写法是这样的,但是一直没有找到错误。

#include
int main()
{
int n,i,sum,t;
sum=0;
while(scanf(“%d”,&n)!=EOF);
{
for(i=0;i

但是HDOJ一直提示WA,也没有找到那里有错误。请教了一下学长,找了好久终于发现while语句后面不应该有分号,否则不会有任何输出…………

鲜血的教训啊……

另附一个正确的写法:

#include
void main()
{
int n,a,i,sum;
while(scanf(“%d”,&n)!=EOF)
{
sum=0;
for(i=0;i

授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。