2020-12-16HDOJ-ACMsteps笔记

2023-02-15,

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

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

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

Sample Output
10
15

#include <stdio.h>
int main()
{
int n,i,a,new,sum=0;
scanf("%d",&n);
i=0;
while (~scanf("%d",&a)&&i<n)
{
while(a--)
{
scanf("%d",&new);
sum+=new;
}
printf("%d\n",sum);
i++;
sum=0;/*一定要把sum重新置零,不然会
带着上一行输入的sum继续做加法*/
}
return 0;
}

也改了许多次才通过.需要特别注意注释处的细节
还有,学到方法while(a–)来代替计数器.

2020-12-16HDOJ-ACMsteps笔记的相关教程结束。

《2020-12-16HDOJ-ACMsteps笔记.doc》

下载本文的Word格式文档,以方便收藏与打印。