# tctony

Focus on linux,emacs,c/c++,python,algorithm...

C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
 17 随笔 :: 0 文章 :: 7 评论 :: 0 Trackbacks

1.

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`
```My Code
#include<iostream>using namespace std;int main(){    int a,b;    while(cin>>a>>b)        cout<<a+b<<endl;    return 1;}
```

2.
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.

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
```2
1 5
10 20```

Sample Output
```6
30```

My Code:
#include<iostream>
using namespace std;
int main ()
{

int n,a,b;
cin
>>n;

while(n--){
cin
>>a>>b;
cout
<<a+b<<endl;
}

return 1;
}

3.
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.

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
0 0```

Sample Output
```6
30```
My Code：
#include<iostream>
using namespace std;

int main()
{

int a,b;

while(cin>>a>>b){

if(a==0 && b==0)    break;
cout
<<a+b<<endl;
}

return 1;
}

4.
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```
`My Code：`
#include<iostream>
using namespace std;

int main() {

int n,p,t;

while(1){
cin
>>n;

if(n==0break;
p
=0;

while(n--){
cin
>>t;
p
+=t;
}

cout
<<p<<endl;
}

return 1;
}

5.
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```
My Code:
#include<iostream>
using namespace std;

int main() {

int n,t,p,x;
cin
>>t;

while(t--){
cin
>>n;
p
=0;

while(n--){
cin
>>x;
p
+=x;
}

cout
<<p<<endl;
}

return 1;
}

6.
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```
My Code:
#include<iostream>
using namespace std;

int main() {

int n,t,p;

while(cin>>n){
p
=0;

while(n--){
cin
>>t;
p
+=t;
}

cout
<<p<<endl;
}

return 1;
}

posted on 2007-11-28 15:33 tctony 阅读(1370) 评论(0)  编辑 收藏 引用