2019.3.23HDOJ-1089~1096,A+B问题系列

版权声明:那啥,咱一个萌新写的东西没啥价值。但是也要打个招呼吧…… https://blog.csdn.net/Miaplacidus/article/details/88771176

因为有同学问我这些题难度如何,所以晚上回寝做一下看看,发现这些题真是入门必做题啊,如果我当初能做到这些题就好了……
注意要仔细读题,在读题和思考上多花些时间,把题看明白,想出思路再去敲代码
这些都是OJ上常见的输入格式处理方法,我感觉是入门必做题

(# ̄▽ ̄)===== HDOJ传送门 =====( ̄▽ ̄*)

提交记录

Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory Code Len. Language Author
28681894 2019-03-23 22:55:37 Accepted 1096 0MS 1692K 252 B C Overstars
28681879 2019-03-23 22:53:34 Presentation Error 1096 0MS 1692K 252 B C Overstars
28681862 2019-03-23 22:51:40 Presentation Error 1096 0MS 1688K 223 B C Overstars
28681859 2019-03-23 22:51:18 Compilation Error 1096 0MS 0K 223 B C Overstars
28681817 2019-03-23 22:47:06 Accepted 1095 15MS 1688K 127 B C Overstars
28681755 2019-03-23 22:41:38 Accepted 1094 0MS 1692K 196 B C Overstars
28681750 2019-03-23 22:41:03 Compilation Error 1094 0MS 0K 196 B C Overstars
28681710 2019-03-23 22:36:47 Accepted 1093 0MS 1696K 221B C Overstars
28681662 2019-03-23 22:32:20 Accepted 1092 15MS 1692K 204 B C Overstars
28681558 2019-03-23 22:23:31 Accepted 1091 0MS 1680K 152 B C Overstars
28681556 2019-03-23 22:23:12 Presentation Error 1091 15MS 1692K 150 B C Overstars
28681474 2019-03-23 22:16:48 Accepted 1090 15MS 1684K 150 B C Overstars
28681377 2019-03-23 22:08:13 Accepted 1089 0MS 1688K 123 B C Overstars

刚刚熄灯,影响室友睡觉好像不太好?

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

题目

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

AC的代码

/*A+B for Input-Output Practice (I)
*35秒看题,1分23秒敲代码+AC*/
#include<stdio.h>
int main(void)
{
	int a,b;
	while(scanf("%d %d",&a,&b)==2){
		printf("%d\n",a+b);
	}
	return 0;
}

35秒看题,1分23秒敲代码+AC。
没什么好说的,注意下scanf()的返回值,判断是否读到文件结束,换成scanf("%d %d",&a,&b)!=EOF也可以

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

题目

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

AC的代码

/*A+B for Input-Output Practice (II)
*46秒看题,1分15秒敲代码,13秒提交*/
#include<stdio.h>
int main(void)
{
	int N,a,b;
	scanf("%d",&N);
	while(N-->0){
		scanf("%d %d",&a,&b);
		printf("%d\n",a+b);
	}
	return 0;
}

46秒看题,1分15秒敲代码,13秒提交。
使用自减运算符计算,来判断什么时候结束读取

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

题目

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

AC的代码

/*A+B for Input-Output Practice (III)
*19秒看题,1分34秒敲代码,47秒修改了一个PE*/
#include<stdio.h>
int main(void)
{
	int a,b;
	while(scanf("%d %d",&a,&b)==2){
		if(a==0&&b==0)
			break;
		printf("%d\n",a+b);
	}
	return 0;
}

19秒看题,1分34秒敲代码,47秒修改了一个PE.
当所有输入数值为0时结束程序,也是很常见的题目要求。

1092-A+B for Input-Output Practice (IV)

题目

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

AC的代码

/*A+B for Input-Output Practice (IV)
*14秒读题,2分11秒敲代码,18秒提交并AC*/
#include<stdio.h>
int main(void)
{
	int N,temp,sum;
	while((scanf("%d",&N)!=EOF)&&N!=0){
		sum=0;
		while(N-->0){
			scanf("%d",&temp);
			sum+=temp;
		}
		printf("%d\n",sum);
	}
	return 0;
}

14秒读题,2分11秒敲代码,18秒提交并AC。
按行读取N个数,每行第一个数为N,且N为0时结束程序。

1093-A+B for Input-Output Practice (V)

题目

A+B for Input-Output Practice (V)
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

AC的代码

/*A+B for Input-Output Practice (V)
*16秒读题,1分48秒敲代码,16秒提交并AC*/
#include<stdio.h>
int main(void)
{
	int m,n;
	scanf("%d",&n);
	while(n-->0){
		scanf("%d",&m);
		int temp,sum=0;
		while(m-->0){
			scanf("%d",&temp);
			sum+=temp;
		}
		printf("%d\n",sum);
	}
	return 0;
}

16秒读题,1分48秒敲代码,16秒提交并AC。
第一个数字为N,表示有N组数据,每行首个数字为M,表示这一组数据有M个

1094-A+B for Input-Output Practice (VI)

题目

A+B for Input-Output Practice (VI)
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

AC的代码

/*A+B for Input-Output Practice (VI)
*36秒读题,1分46秒敲代码,53秒修改了一个CE后AC*/
#include<stdio.h>
int main(void)
{
	int N,sum,temp;
	while(scanf("%d",&N)!=EOF){
		sum=0;
		while(N-->0){
			scanf("%d",&temp);
			sum+=temp;
		}
		printf("%d\n",sum);
	}
	return 0;
}

36秒读题,1分46秒敲代码,53秒修改了一个CE后AC。
因为不知道一共有多少组,所以要判断scanf()的返回值来决定什么时候结束。

1095-A+B for Input-Output Practice (VII)

A+B for Input-Output Practice (VII)
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

AC的代码

/*A+B for Input-Output Practice (VII)
*11秒看题,54秒敲代码,17秒提交并AC*/ 
#include<stdio.h>
int main(void)
{
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		printf("%d\n\n",a+b);
	}
	return 0;
}

11秒看题,54秒敲代码,17秒提交并AC.
这个系统判题还蛮松的,因为输入数据多少组未知,无法判断是否是最后一行,所以直接多敲一个\n就可以了。
可以看出来它的样例输出的最后一行也是空行

1096-A+B for Input-Output Practice (VIII)

题目

A+B for Input-Output Practice (VIII)
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

AC的代码

/*A+B for Input-Output Practice (VIII)
*9秒读题,2分23秒敲代码,4分36秒修改了一个CE和PE后AC*/ 
#include<stdio.h>
int main(void)
{
	int n,m,temp,sum;
	scanf("%d",&n);
	while(n-->0){
		scanf("%d",&m);
		sum=0;
		while(m-->0){
			scanf("%d",&temp);
			sum+=temp;
		}
		printf("%d\n",sum);
		if(n!=0)
			putchar('\n');
	}
	return 0;
}

9秒读题,2分23秒敲代码,4分36秒修改了一个CE和PE后AC。
和1093的区别在于每两个输出数据都要间隔一空行,但是最后一个输出数据后不能有空行。
当最后一轮迭代时,注意本轮n–的式子值为1,但此条语句结束后,n的值为0,所以可以通过比较n的值来判断是否输出\n

最后吐槽

这些例题所有的CE都是因为我把scanf()敲成了scnaf()。(ノ`Д)ノ
一定要好好读题,别学我。
如果还没做过OJ题的话,这些题都是必做题,推荐都要做一遍,都是很经典的数据输入格式,做了能少走一点弯路。

2019年3月23日23点35分

猜你喜欢

转载自blog.csdn.net/Miaplacidus/article/details/88771176
今日推荐