(一)
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.
#include <iostream>
using namespace std;
int main()
{
int n,N;
cin>>N;
while(N>0)
{
int i=1,s=0,a;
cin>>n;
for(; i<=n; i++)
{
cin>>a;
s+=a;
}
cout<<s<<endl;
N--;
}
return 0;
}
(二)
Description
Your task is to calculate the sum of some integers.
Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.
/* All rights reserved.
* 文件名称:test.cpp
* 作者:陈丹妮
* 完成日期:2015年 4 月 21 日
* 版 本 号:v1.0
*/
#include <iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int i=1,s=0,a;
for(; i<=n; i++)
{
cin>>a;
s+=a;
}
cout<<s<<endl;
}
return 0;
}
(三)
Description
Your task is to Calculate a + b.
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.
#include <iostream>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m)
{
cout<<n+m<<endl<<endl;;
}
return 0;
}
(四)
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 you must note that there is a blank line between outputs.
#include <iostream>
using namespace std;
int main()
{
int n,N;
cin>>N;
while(N>0)
{
int i=1,s=0,a;
cin>>n;
for(; i<=n; i++)
{
cin>>a;
s+=a;
}
cout<<s<<endl<<endl;
N--;
}
return 0;
}
心得体会:看清题目所要求的条件,按要求输出。这就要求我们,即使再简单的题目,也要细心,细心,再细心!