HDU 1089-1096 A+B for Input-Output Practice(IO系列)

举报
用户已注销 发表于 2021/11/19 05:11:01 2021/11/19
【摘要】 题目: Description Your task is to Calculate a + b.  Too easy?! Of course! I specially designed the problem for acm beginners.  You must ...

题目:

Description

Your task is to Calculate a + b. 
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

代码:

#include<iostream>
using namespace std;

int main()
{
	int a, b;
	while (cin >> a >> b)cout << a + b << endl;
	return 0;
}

题目:

Description

Your task is to Calculate a + b. 

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. 

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

代码:

#include<iostream>
using namespace std;

int main()
{
	int n, a, b;
	cin >> n;
	while (n--)
	{
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

题目:

Description

Your task is to Calculate a + b.

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

代码:

#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 0;
}

题目:

Description

Your task is to Calculate the sum of some integers. 

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

代码:

#include<iostream>
using namespace std;

int main()
{
	int n, a, sum;
	while (cin >>n)
	{
		if (n == 0)break;
		sum = 0;
		while (n--)
		{
			cin >> a;
			sum += a;
		}
		cout << sum << 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 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

代码:

#include<iostream>
using namespace std;

int main()
{
	int t, n, a, sum;
	cin >> t;
	while (t--)
	{
		cin >> n;
		sum = 0;
		while (n--)
		{
			cin >> a;
			sum += a;
		}
		cout << sum << endl;
	}
	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. 

Sample Input

4 1 2 3 4
5 1 2 3 4 5

Sample Output

10
15

代码:

#include<iostream>
using namespace std;

int main()
{
	int n, a, sum;
	while (cin >> n)
	{
		sum = 0;
		while (n--)
		{
			cin >> a;
			sum += a;
		}
		cout << sum << 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. 

Sample Input

1 5
10 20

Sample Output

6

30

代码:

#include<iostream>
using namespace std;

int main()
{
	int a, b;
	while (cin >> a >> b)cout << a + b << 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. 

Sample Input

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

Sample Output

10

15

6

代码:

#include<iostream>
using namespace std;

int main()
{
	int t, n, a, sum;
	cin >> t;
	while (t--)
	{
		cin >> n;
		sum = 0;
		while (n--)
		{
			cin >> a;
			sum += a;
		}
		cout << sum << endl;
		if (t)cout << endl;
	}
	return 0;
}

文章来源: blog.csdn.net,作者:csuzhucong,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/nameofcsdn/article/details/52162676

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。