新手入门 acm 输入输出练习

举报
谙忆 发表于 2021/05/28 07:47:34 2021/05/28
【摘要】 A + B Problem(1000) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 355051    Accepted Submission(s): 110841 Problem Descr...

A + B Problem(1000)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 355051    Accepted Submission(s): 110841

Problem Description
Calculate  A + B.
 
Input
Each line will contain two integers  A and  B. Process to end of file.
 
Output
For each case, output  A + B in one line.
 
Sample Input
1 1
 
Sample Output
2
 
 
题意:每一行输入包含两个整数a和b,每个案例输出a+b的值,在一行;
详见代码,
复制代码
#include<stdio.h>
int main()
{ int a,b,sum; while(scanf("%d%d",&a,&b)!=EOF) {
sum
=a+b; printf("%d\n",sum); } return 0; }
复制代码

 

Sum Problem(1001)

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 237995    Accepted Submission(s): 58229

Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
 
Input
The input will consist of a series of integers n, one integer per line.
 
Output
For each case,  output SUM(n) in one line,  followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
 
Sample Input
1
100
 
Sample Output
1
 
5050
 
 
  题意:每行将输入一个整数n,对于每个案例,输出SUM(n) = 1 + 2 + 3 +  ... + n<求1到n的和> 在一行,紧随其后的是一个空行。
 
其他的就没什么可以注意的了。
详见代码:
复制代码
#include<stdio.h>
int main()
{ int n,i,sum; while(scanf("%d",&n)!=EOF) { for(sum=0,i=0;i<=n;i++) sum=sum+i; printf("%d\n\n",sum); } return 0;
}
复制代码

 

 

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

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 68193    Accepted Submission(s): 37929

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 5
10 20
 
Sample Output
6
30
 
题意:输入整数a和b,用空格分隔,每行一对整数。对于每一对输入整数a和b你应该输出他们的总和,输入a和b占在一行,输出占一行。
貌似和1000是一样的,o(∩_∩)o 哈哈!
复制代码
#include<stdio.h>
int main()
{ int a,b,sum; while(scanf("%d%d",&a,&b)!=EOF) {
sum
=a+b; printf("%d\n",sum); } return 0; }
复制代码

 

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

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 51355    Accepted Submission(s): 33780

Problem 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
 
 
题意:输入包含一个整数N在第一行,然后有N数据。每一行包含一对整数a和b,用空格分隔,每行一对整数。
     对于每一对输入整数a和b你应该输出的总和,a和b在一行,输出输入各占一行。
比较1089,在1089的基础上多了一个控制输入测试的组数N,其他的一样。有木有。
详见代码;
复制代码
#include<stdio.h>
int main()
{ int a,b,t,sum; scanf("%d",&t); while(t--) { scanf("%d%d",&a,&b); sum=a+b; printf("%d\n",sum); } return 0;
}
复制代码

 

 

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

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 60600    Accepted Submission(s): 31168

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 5
10 20
0 0
 
Sample Output
6
30
 
题意:输入包含多个测试用例。每个测试用例包含一对整数a和b,一对整数占一行。当输入测试用例为0 0时,终止输入和测试用例是不被处理。对于每一对输入整数a和b你应该输出他们的总和,a和b在一行,输出在一行。
 
比较1091,不一样的地方就是结束输入的条件不一样,其他的不变,有木有。
详见代码:
复制代码
#include<stdio.h>
int main()
{ int a,b,sum; while(scanf("%d%d",&a,&b)!=EOF) { if(a==0&&b==0)break; sum=a+b; printf("%d\n",sum); } return 0;
}
复制代码

 

 

 

A+B for Input-Output Practice (IV)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 53974    Accepted Submission(s): 28848

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 4
5 1 2 3 4 5
0
 
Sample Output
10
15
 
 
题意:输入包含多个测试用例。每个测试用例包含一个整数N,然后在同一行输入N个整数,。当测试用例是0时,终止输入和测试用例是不被处理。每组输出整数之和占一行,即,一行输入一行输出。
 
比较前面几题,这题稍微有点区别但变幻不大,N用来控制整数的个数。然后最后以0结束测试,
 
详见代码:
复制代码
#include<stdio.h>
int main()
{ int a[100],t,i,sum; while(scanf("%d",&t)!=EOF) { if(t==0) break; sum=0; for(i=1;i<=t;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } printf("%d\n",sum); } return 0;
}
复制代码

 

 

A+B for Input-Output Practice (V)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 39483    Accepted Submission(s): 26698

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
2
4 1 2 3 4
5 1 2 3 4 5
 
Sample Output
10
15
 
 
题意:输入包含一个整数N在第一行,然后有N行测试用例,每一行都始于一个整数M,然后有M整数在同一个行。
每组输出整数之和且输出占一行,一行输入一行输出。
 
反思:是不是前两题的集合体哈,再仔细看看就知道了。有木有!
 
详见代码:
复制代码
#include<stdio.h>
int main()
{ int a[100],t,i,p,sum; scanf("%d",&p); while(p--) { scanf("%d",&t); if(t==0) break; sum=0; for(i=1;i<=t;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } printf("%d\n",sum); } return 0;
}
复制代码

 

 

A+B for Input-Output Practice (VI)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37174    Accepted Submission(s): 25051

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
5 1 2 3 4 5
 
Sample Output
10
15
 
 
 
这题就不要在啰嗦的在写题意了吧,貌似和上面的题目太像了,,,,o(∩_∩)o 哈哈
详见代码:
复制代码
#include<stdio.h>
int main()
{ int a[100],t,i,sum; while(scanf("%d",&t)!=EOF) { sum=0; for(i=1;i<=t;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } printf("%d\n",sum); } return 0;
}
复制代码


看到这里我只想说,大家做题时候,代码写的格式一定要规范,最好就是形式统一,该空的时候就空格,不然代码都一个水平面就美观了,而且以后比赛的时候你还有2个队友,让他们给你检查错误的话,你的代码又不整洁,那么效率肯定不会高的,而且会有厌烦的心态,那就更好了,所以大家以后写代码尽量规范一点。就是这样了!

 

 

 

 

A+B for Input-Output Practice (VII)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 36617    Accepted Submission(s): 24438

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 5
10 20
 
Sample Output
6
 
30
 
 
题意:输入2个整数a和b,用空格分隔,每行一对整数。对于每一对输入整数a和b你应该输出他们的总和,a和b,身后跟着一个空行。
 
是不是又忘记空行了,输出的时候,这次又是中间再空一行哦,所以做题的时候一定要先看清楚题目的具体要求在动手编程,不然只会白白丢分!
 
详见代码:
复制代码
#include<stdio.h>
int main()
{ int a,b,sum; while(scanf("%d%d",&a,&b)!=EOF) { sum=a+b; printf("%d\n\n",sum); } return 0;
}
复制代码

 

 

 


终于快结束了,,,,,,搞得好辛苦,大家一定要认真对待啊!

 

 

 

 

A+B for Input-Output Practice (VIII)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 78908    Accepted Submission(s): 24263

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
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
 
Sample Output

10

 
15
 
6
 
 
题意:输入包含一个整数N在第一行,然后有N行测试数据。每一行都开始都有一个整数M,然后后面有M个整数在同一行。
每组输出整数之和,输出占一行,你必须注意,输出,每行之间有一个空行。
 
我只能说这题就是上面几道题目的大集合吧,所以是不是很简单呢。哈哈,所以对于acm的输入输出是不是有所了解了呢,
  对!就是那么简单!so easy!    o(∩_∩)o    那么,,,
 
 
是先看代码吧,
复制代码
#include<stdio.h>
int main()
{ int a[100],t,i,p,sum; scanf("%d",&p); while(p--) { scanf("%d",&t); sum=0; for(i=1;i<=t;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } printf("%d\n",sum); if(p)//中间空行用 printf("\n"); } return 0;
}
复制代码

 

 


到现在为止,你已经学会acm的简单输入输出了,(当然不是所有的输入输出,这个留给以后慢慢学习好了,)那么现在你已经可以在杭电上A题了,(为自己鼓掌,哈哈),接下来大家可以从简单题下手,本人建议可以先做11页的题。

当然不会的题欢迎到群内讨论,QQ群:  <主要面向刚刚入门的13级新生!>

最后还有一个小小的建议:学习贵在坚持!刚刚开始都是比较难的,所以大家要相互鼓励相互监督,共同进步!

谢谢你的浏览!o(∩_∩)o

 
转载请注明出处:http://www.cnblogs.com/yuyixingkong/ 自己命运的掌控着!

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

原文链接:chenhx.blog.csdn.net/article/details/48088947

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

评论(0

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

全部回复

上滑加载中

设置昵称

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

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

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