# 【ACM】入门训练之A+B

A答：Hello World
B答：A+B

## A+B for Input-Output Practice (I)

Problem Description

Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

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 in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20

Sample Output

6
30

sanwa：我感觉吧，这道题目我还是会做的，像我这么菜的都会的题，肯定没什么说的啦。可能需要注意的点就是输入的样例数是没有限制的，注意输入结束条件即可。我贴下代码，大佬看看有没有什么错或者改进的地方^_^

#include <iostream>
using namespace std;
int main(){
long a,b;
while(cin>>a>>b){
cout<<a+b<<endl;
}
return 0;
}

## A+B for Input-Output Practice (II)

INPUT

Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.

sanwa：这道题目和前边不一样的地方在于，确定了输入的数据数量，另外注意的是两道题目的A和B都是integer。大佬看看有没有什么错或者改进的地方^_^

#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
long a,b;
cin>>a>>b;
cout<<a+b<<endl;
}
return 0;
}

## A+B for Input-Output Practice (III)

Input

Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

sanwa：这个主要是读懂当A和B都同时为零时结束输入，如何构造这种情况呢？

#include <iostream>
using namespace std;
int main(){
long a,b;
while(cin>>a>>b){
if(a == b && b == 0){
break;
}
cout<<a+b<<endl;
}
return 0;
}

## A+B for Input-Output Practice (IV)

Problem Description

Input

Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

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

4 1 2 3 4
5 1 2 3 4 5
0

Sample Output

10
15

sanwa：很显然，这道题目感觉就是前边三道题目的一个综合，有样例数据的结束条件（输入0），也有单个样例的输入结束条件（给定了n）。sanwa的代码是这样写的，但感觉不是很优雅，大佬看看给下更优雅美观的代码 ^_^

#include <iostream>
using namespace std;
int main(){
int n;
while(cin>>n, n != 0){
long long res = 0;
while(n--){
int temp;
cin>>temp;
res += temp;
}
cout<<res<<endl;
}
return 0;
}

## A+B for Input-Output Practice (V)

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.

sanwa：这道题目主要也是前三道题目的综合，用integer N限定了样例数，用integer M限定了单个样例的数据量. dalao dalao，给我看看代码，^_^

#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
int m;
cin>>m;
long long res = 0;
while(m--){
int temp;
cin>>temp;
res += temp;
}
cout<<res<<endl;
}
return 0;
}

## A+B for Input-Output Practice (VI)

Problem Description

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.

Sample Input

4 1 2 3 4
5 1 2 3 4 5

Sample Output

10
15

sanwa : 这道题目看着感觉怪怪的，就直接给出了这个，感觉有点突兀。但细想下，还是practice I、II、III的一个综合。也就是没有限制样例数目（以文件结尾为结束），单个样例用integer n来限定

#include <iostream>
using namespace std;
int main(){
int n;
while(cin>>n){
long long res = 0;
while(n--){
int temp;
cin>>temp;
res += temp;
}
cout<<res<<endl;
}
return 0;
}

## A+B for Input-Output Practice (VII)

Problem Description

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.

Sample Input

1 5
10 20

Sample Output

6

30

#include <iostream>
using namespace std;
int main(){
long a,b;
while(cin>>a>>b){
cout<<a+b<<endl<<endl;
}
return 0;
}

## A+B for Input-Output Practice (VIII)

Problem Description

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

sanwa：这个题目可谓是前边各个问题的大综合了，用N去限定样例数目，用M去限定单个样例的数据量，然后输出结果之间都要求要有一个空行，对于这个输出空行，因为不是每一个样例结果都输出空行，我使用了一个标识，dalao们一般都是怎么做的呢？^_^。

#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
bool flag = false;
while(n--){
int m;
cin>>m;
long long res = 0;
while(m--){
int temp;
cin>>temp;
res += temp;
}
if(flag){
cout<<endl;
} else{
flag = true;
}
cout<<res<<endl;
}
return 0;
}


## 总结

dalao们，文中有错误的地方，在此处跪求指正，另外对于我们这些小白有什么建议的还望不吝赐教，^_^