【ACM竞赛入门】001.一文读懂常见的ACM题型输入输出格式
创始人
2025-05-28 05:13:09
0

文章目录

    • A+B for Input-Output Practice (I)
    • A+B for Input-Output Practice (II)
    • A+B for Input-Output Practice (III)
    • A+B for Input-Output Practice (IV)
    • A+B for Input-Output Practice (V)
    • A+B for Input-Output Practice (VI)
    • A+B for Input-Output Practice (VII)
    • A+B for Input-Output Practice(VIII)

本文通过各种类型的A+B题目来帮助大家快速了解ACM题目中常见的输入输出格式,帮助大家快速上手

A+B for Input-Output Practice (I)


时间限制: 1s 内存限制: 64MB

题目描述

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

输入格式

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

输出格式

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.

样例输入

1 5
10 20

样例输出

6
30

AC代码(C语言)

#includeint main(){//freopen("data.in.txt","r",stdin);int a,b;while(~scanf("%d%d",&a,&b)){printf("%d\n",a+b);} return 0;
} 

A+B for Input-Output Practice (II)


时间限制: 1s 内存限制: 64MB

题目描述

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

输入格式

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

输出格式

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.

样例输入

2
1 5
10 20

样例输出

6
30

AC代码(C语言)

#includeint main(){
//	freopen("data.in.txt","r",stdin);int a,b,n;scanf("%d",&n);while(n--){	scanf("%d%d",&a,&b);printf("%d\n",a+b);} return 0;
} 

A+B for Input-Output Practice (III)


时间限制: 1s 内存限制: 64MB

题目描述

Your task is to Calculate a + b.

输入格式

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.

输出格式

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.

样例输入

1 5
10 20
0 0

样例输出

6
30

AC代码(C语言)

#includeint main(){
//	freopen("data.in.txt","r",stdin);int a,b;while(~scanf("%d%d",&a,&b)){if(a==0&&b==0) break;	printf("%d\n",a+b);} return 0;
} 

A+B for Input-Output Practice (IV)


时间限制: 1s 内存限制: 64MB

题目描述

Your task is to Calculate the sum of some integers.

输入格式

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.

输出格式

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.

样例输入

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

样例输出

10
15

AC代码(C语言)

#include
int main(){//freopen("data.in.txt","r",stdin);int n,sum=0,tmp;while(~scanf("%d",&n)){sum=0;if(n==0) break;while(n--){scanf("%d",&tmp);sum+=tmp;}printf("%d\n",sum);}return 0; 
}

A+B for Input-Output Practice (V)


时间限制: 1s 内存限制: 64MB

题目描述

Your task is to calculate the sum of some integers.

输入格式

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.

输出格式

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.

样例输入

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

样例输出

10
15

AC代码(C语言)

#include
int main(){//freopen("data.in.txt","r",stdin);int n,m,sum=0,tmp;scanf("%d",&n);while(n--){sum=0;scanf("%d",&m);while(m--){scanf("%d",&tmp);sum+=tmp;}	printf("%d\n",sum);}return 0; 
}

A+B for Input-Output Practice (VI)


时间限制: 1s 内存限制: 64MB

题目描述

Your task is to calculate the sum of some integers.

输入格式

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.

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.

样例输入

4 1 2 3 4
5 1 2 3 4 5

样例输出

10
15

AC代码(C语言)

#include
int main(){//freopen("data.in.txt","r",stdin);int n,sum=0,tmp;while(~scanf("%d",&n)){sum=0;while(n--){scanf("%d",&tmp);sum+=tmp;}	printf("%d\n",sum);}return 0; 
}

A+B for Input-Output Practice (VII)


时间限制: 1s 内存限制: 64MB

题目描述

Your task is to Calculate a + b.

输入格式

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

输出格式

For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.

样例输入

1 5
10 20

样例输出

6

30

AC代码(C语言)

#include
int main(){//freopen("data.in.txt","r",stdin);int a,b;while(~scanf("%d%d",&a,&b)){printf("%d\n\n",a+b);}return 0; 
}

A+B for Input-Output Practice(VIII)


时间限制: 1s 内存限制: 64MB

题目描述

Your task is to calculate the sum of some integers

输入格式

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

输出格式

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.

样例输入

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

样例输出

10

15

6

AC代码(C语言)

#include
int main(){//freopen("data.in.txt","r",stdin);int n,m,tmp,sum=0;scanf("%d",&n);while(n--){sum=0;scanf("%d",&m);while(m--){scanf("%d",&tmp);sum+=tmp;}printf("%d\n\n",sum);}return 0; 
}

相关内容

热门资讯

消防安全黑板报内容 消防安全黑板报内容  如果发现火灾发生,最重要的是报警,这样才能及时扑救,控制火势,减轻火灾造成损失...
网络安全知识小报内容 网络安全知识小报内容  在这飞速发展的科技时代,网络安全尤为的重要。可能很多用户都不知道什么是网络安...
辞旧迎新黑板报图片大全   辞旧迎新,辞:告别。迎:迎接。辞旧迎新指的是告别旧的一年,迎接新的一年的到来,即庆贺新年的意思。...
英语手抄报图片简单又漂亮四年...   英语手抄报可以拉近老师和小伙伴的距离,下面由unjs小编为大家带来的四年级英语手抄报图片简单又漂...
春节手抄报简单又漂亮图片 春节手抄报简单又漂亮图片大全  引导语:春节是我国最为隆重的传统节日,亦是家家户户团圆的日子,那么要...
教师节手抄报内容 教师节手抄报内容  每年的教师节,中国各地的教师都以不同方式庆祝自己的节日。通过评选和奖励,介绍经验...
清明节手抄报简单又漂亮三年级 4月2日,清明节来临之际,我们新桥中心小学由校长牵头,由少先队大队部组织,由少先队辅导员、全体少先队...
有趣的汉字手抄报内容 有趣的汉字手抄报内容  在学习和工作中,大家都知道手抄报吧,手抄报除报头按内容设计、绘制外,每篇文章...
防溺水黑板报:防溺水知识 防溺水黑板报:防溺水知识  知识:  1到公园划船,或乘坐船时必须要坐好,不要在船上乱跑,或在船舷边...
文明礼仪和诚信的手抄报图片 文明礼仪和诚信的手抄报图片大全  我国是世界四大文明古国之一,古老的中华民族自古以来就享有“礼仪之邦...
尚德守法共治共享食品安全主题...   近日,国务院食安办、卫计委、食药监总局等17部门联合下发《关于开展2016年全国食品安全宣传周活...
绿色校园手抄报资料 绿色校园手抄报资料  校园是我们学习成长的地方,为此,建设绿色校园是首要任务,不论是校领导还是在校学...
学雷锋做好事手抄报 学雷锋做好事手抄报  雷锋精神体现在一个个具体行为当中,我们对雷锋精神的理解也是从他的具体行为认识的...
中国传统文化黑板报 中国传统文化黑板报  在日复一日的学习、工作生活中,大家一定都接触过黑板报吧,黑板报具有宣传和传递信...
开学黑板报图片 开学黑板报图片(1)开学黑板报图片(2)开学黑板报图片(3)  秋季开学祝福语  1、 假期的尽头是...
做一个有道德的人手抄报内容 做一个有道德的人手抄报内容导语:人们常说:道德是石,敲出希望之火;道德是火,点燃希望之灯;道德是灯,...
小学生清明节手抄报画 小学生清明节手抄报画  每逢清明节(当然其它日子亦可),我们应前往先人的长眠处祭奠,献上一束鲜花,献...
交通规则手抄报 交通规则手抄报大全  交通规则记得牢,一路平安大家好。做交通安全手抄报可以提高学生的交通安全意识。下...
文明进校园手抄报内容   文明,是历史以来沉淀下来的,有益增强人类对客观世界的适应和认知、符合人类精神追求、能被绝大多数人...
剪纸爱心喜字剪法步骤 剪纸爱心喜字剪法步骤  想必上一辈老人都会用剪刀剪个大大的`喜字,尤其是在一些节日中,为了迎一个喜气...