前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ACM入门(占个位)

ACM入门(占个位)

作者头像
Cloud-Cloudys
发布2020-07-07 15:31:22
4820
发布2020-07-07 15:31:22
举报
文章被收录于专栏:ShanSan的云原生之路

A+B for Input-Output Practice(using C++)

1.

Problem 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 61 20

Sample Output

721

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int x,y;
	while(cin>>x>>y)
	{
		cout<<x+y<<endl;
	}
	return 0;
}

2.

Problem Description

The first line integer means the number of input integer a and b. Your task is to Calculate a + b.

Input

Your task is to Calculate a + b. The first line integer means the numbers of pairs of input integers.

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

210 2022 36

Sample Output

3058

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int n,i;
	int a,b;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	return 0;
}

3.

Problem 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 510 200 0

Sample Output

630

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	while(cin>>a>>b)
	{
		if(a==0&&b==0)break;
		else
		    cout<<a+b<<endl;
	}
	return 0;
}

4.

Problem 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 45 1 2 3 4 50

Sample Output

1015

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0)return 0;
		int x,sum=0;
		while(n--)
		{
			cin>>x;
			sum+=x;
		}
		cout<<sum<<endl;
	}
	return 0;
}

5.

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

24 1 2 3 45 1 2 3 4 5

Sample Output

1015

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int N;
	int i;
	int n,x;
	cin>>N;
	for(i=0;i<N;i++)
	{
		int n;
		int x,sum=0;
		cin>>n;
		while(n--)
		{
			cin>>x;
			sum += x;
		}
		cout<<sum<<endl;
	}
	return 0;
}

6.

Problem 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 55 1 2 3 4 5

Sample Output

1015

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int n;
	int x,sum=0;
	while(cin>>n)
	{
		while(n--)
		{
			cin>>x;
			sum +=x;
		}
		cout<<sum<<endl;
		sum=0;
	}
	return 0;
}

7.

Problem 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 510 20

Sample Output

630

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int x,y;
	while(cin>>x>>y)
	{
		cout<<x+y<<endl;
		cout<<endl;
	}
	return 0;
}

8.

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 you must note that there is a blank line between outputs.

Sample Input

34 1 2 3 45 1 2 3 4 56 1 2 3 4 5 6

Sample Output

101521

代码语言:javascript
复制
#include<iostream>
using namespace std;
int main()
{
	int N;
	int n,x;
	int sum=0;
	cin>>N;
	while(N--)
	{
		cin>>n;
		while(n--)
		{
			cin>>x;
			sum +=x;
		}
		cout<<sum<<endl;
		cout<<endl;
		sum=0;
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年10月2日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A+B for Input-Output Practice(using C++)
    • 1.
      • 2.
        • 3.
          • 4.
            • 5.
              • 6.
                • 7.
                  • 8.
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档