hdu 1093 A+B for Input-Output Practice (V)
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
中文翻译
您的任务是计算一些整数的总和。
输入项
输入的第一行包含一个整数N,然后是N行。每行以整数M开头,然后在同一行中跟随M个整数。
输出量
对于每组输入整数,应在一行中输出其总和,并且在输入中每行输出一行。
代码
#include<stdio.h>
int main(){
int i,j;
int a;
int m,str[1000];
int sum = 0;
while(scanf("%d",&a)!=EOF){
for (i = 0; i < a ; i++)
{
scanf("%d",&m);
for(j = 0,sum = 0; j < m; j++){
scanf("%d",&str[j]);
sum += str[j];
}
printf("%d\n",sum);
}
}
}