题目:
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 you must note that there is a blank line between outputs.
Sample Input
3 4 1 2 3 4 5 1 2 3 4 5 3 1 2 3
Sample Output
10 15 6
题意:
给你一个n,代表有n组测试数据,然后后面的n行,每一行的第一个数字m代表要求后面的m个数字的和;
格式需要注意,每两个结果之间有一个空行。
代码如下:
JAVA:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n,m,a,s;
n=input.nextInt();
while(n-->0) {
m=input.nextInt();
s=0;
for(int i=0;i<m;i++) {
a=input.nextInt();
s=s+a;
}
System.out.println(s);
if(n!=0)
System.out.println();
}
}
}
C++:
#include<stdio.h>
int main()
{
int N;
scanf("%d",&N);
while(N--)
{
int i,M,n,sum=0;
scanf("%d",&M);
for(i=0;i<M;i++)
{
scanf("%d",&n);
sum=sum+n;
}
printf("%d\n",sum);
if(N!=0)
printf("\n");
}
return 0;
}