ACM---1089: A+B for Input-Output Practice (V)
2014-11-16 06:37
344 查看
题目描述
Your task is to calculate the sum of some integers.
输入
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.
输出
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.
样例输入
2
4 1 2 3 4
5 1 2 3 4 5
样例输出
10
15
代码如下:
#include<stdio.h>
int main(void)
{
int n, m, a, sum, i, j;
while(scanf("%d", &n) != EOF)
{
for(i = 0; i < n; i ++)
{
scanf("%d", &m);
sum = 0;
for(j = 0; j < m; j ++)
{
scanf("%d", &a);
sum = sum + a;
}
printf("%d\n", sum);
}
}
return 0;
}
Your task is to calculate the sum of some integers.
输入
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.
输出
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.
样例输入
2
4 1 2 3 4
5 1 2 3 4 5
样例输出
10
15
代码如下:
#include<stdio.h>
int main(void)
{
int n, m, a, sum, i, j;
while(scanf("%d", &n) != EOF)
{
for(i = 0; i < n; i ++)
{
scanf("%d", &m);
sum = 0;
for(j = 0; j < m; j ++)
{
scanf("%d", &a);
sum = sum + a;
}
printf("%d\n", sum);
}
}
return 0;
}
相关文章推荐
- 杭电ACM 1089:A+B for Input-Output Practice (I)
- 杭电ACM 1089 A+B for Input-Output Practice (I)
- 杭电ACM 1089(A+B for Input-Output Practice (I))
- 1089 A+B for Input-Output Practice (I)
- ACM路程----1085 A+B for Input-Output Practice (I)
- 1089 A+B for Input-Output Practice (I)
- 武汉科技大学ACM :1004: A+B for Input-Output Practice (IV)
- 杭电ACM 1096: A+B for Input-Output Practice (VIII)
- 杭电ACM 1090 (A+B for Input-Output Practice (II))
- hdu 1089 A+B for Input-Output Practice (I)
- 「HD_ACM」 A+B for Input-Output Practice (II)
- 【杭电oj1089】A+B for Input-Output Practice (I)
- ACM----1086 A+B for Input-Output Practice (II)
- 武汉科技大学ACM :1005: A+B for Input-Output Practice (V)
- 杭电ACM 1.1.8 A+B for Input-Output Practice (VIII)
- 1089-A+B for Input-Output Practice (I)
- 杭电ACM 1091(A+B for Input-Output Practice (III))
- HDU 1089 A+B for Input-Output Practice (I)
- 「HD_ACM」A+B for Input-Output Practice (III)
- 山东理工 ACM [1011] A+B for Input-Output Practice (II)