acm编程相加的问题

来源:百度知道 编辑:UC知道 时间:2024/06/11 02:12:24
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

用 C或C++ 编程,谢谢。
2代表两行,每行第一个数字代表相加数的个数,输出为后面几个数相加 。

#include <stdio.h>

int main(int argc, char *argv[]){
long n, m, tmp, sum;
scanf("%ld\n", &n);
while(n --){
scanf("%ld", &m);
sum = 0;
while(m --){
scanf("%ld", &tmp);
sum += tmp;
}
printf("%ld\n", sum);
}
return 0;
}

你没给出数据范围,暂时用long。