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
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
code:
#include<iostream>
using namespace std;
int main()
{
int n,m,x,sum;
cin>>n;
while(n--)
{
cin>>m;
sum=0;
while(m--)
{
cin>>x;
sum+=x;
}
cout<<sum<<endl;
}
return 0;
}
本文介绍了一个经典的编程练习题“A+B for Input-Output Practice (V)”,该题要求计算每组输入整数的总和,并详细展示了使用C++语言实现此功能的具体代码。通过阅读本文,读者可以了解如何处理多组输入数据并计算它们的和。

被折叠的 条评论
为什么被折叠?



