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,然后用while(n--){}来控制输入数据的组数。
AC源代码(C语言):
 1 #include<stdio.h>
 2 int main()
 3 {
 4   int n,a,b,s,i;
 5   scanf("%d",&n);
 6   while(n--)
 7   { 
 8     s=0;
 9     scanf("%d",&a);
10     for(i=1;i<=a;i++)
11     {
12       scanf("%d",&b);
13       s+=b;                 
14     }
15     printf("%d\n",s);                                                        
16   }  
17  return 0;     
18 }

 2013-01-29

posted @ 2013-01-29 16:37  刘一卜  阅读(2392)  评论(0编辑  收藏  举报