hud—ABCDEFGHKLM
A~H 考数据输入输出,用到while scanf 等;
A+B for Input-Output Practice (I)
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
Inputcopy | Outputcopy |
---|---|
1 5 10 20 | 6 30 |
#include<stdio.h>
int main(){
int a,b;
while(~scanf("%d%d",&a,&b)){
printf("%d\n",a+b);
}
return 0;
}
B - A+B for Input-Output Practice (II)
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
Inputcopy | Outputcopy |
---|---|
2 1 5 10 20 | 6 30 |
#include<stdio.h>
int main(){
int n,a,b;
scanf("%d",&n);
while(n--){
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
return 0;
}
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
Inputcopy | Outputcopy |
---|---|
1 5 10 20 0 0 | 6 30 |
这道题的要求是a+b的程序在读取到两个0 0的时候会退出循环
且代码不会处理这两个0 0(把它们当作循环结束标志)
#include <stdio.h>
int main()
{
int a = 0, b = 0, c;
while (1)
{
scanf("%d%d", &a, &b);
if (a == 0 && b == 0)//判断键入的是否为0 0
{
break;//是0 0,退出循环
}
else//不是0 0,继续运行a+b
{
c = a + b;
printf("%d\n", c);
}
}
return 0;
}
A+B for Input-Output Practice (IV)
D - A+B for Input-Output Practice (IV)
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
Inputcopy | Outputcopy |
---|---|
4 1 2 3 4 5 1 2 3 4 5 0 | 10 15 |
#include<stdio.h>
int main()
{
int n, sum, i, t;
while (scanf("%d", &n) != EOF && n != 0) //判断是否等于0
{
sum = 0;
for (i = 0; i < n; i++)
{
scanf("%d", &t);
sum = sum + t;//不断往sum里面加数字
}
printf("%d\n", sum);
}
}
与前面的两个数字相加不同,这道题的要求是,先输入你需要相加的数字的个数,再依次键入数字
遇到0的时候停止循环
- 这个0必须是第一个数字,即代表需要“0个数字相加”
- 如果是需要相加的数字里有0,不应退出循环
A+B for Input-Output Practice (V)
E - A+B for Input-Output Practice (V)
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
Inputcopy | Outputcopy |
---|---|
2 4 1 2 3 4 5 1 2 3 4 5 | 10 15 |
#include<stdio.h>
int main()
{
int n, a, b, i, j, sum;
sum = 0;
while (scanf("%d\n", &n) != EOF)
{
for (i = 0; i < n; i++)
{
scanf("%d", &b);
for (j = 0; j < b; j++)
{
scanf("%d", &a);
sum += a;
}
printf("%d\n", sum);
sum = 0;
}
}
}
A+B for Input-Output Practice (VI)
F - A+B for Input-Output Practice (VI)
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
Inputcopy | Outputcopy |
---|---|
4 1 2 3 4 5 1 2 3 4 5 | 10 15 |
#include<stdio.h>
int main()
{
int n, sum, i, t;
while (scanf("%d", &n) != EOF)
{
sum = 0;
for (i = 0; i < n; i++)
{
scanf("%d", &t);
sum = sum + t;
}
printf("%d\n", sum);
}
}
A+B for Input-Output Practice (VII)
G - A+B for Input-Output Practice (VII)
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
Inputcopy | Outputcopy |
---|---|
1 5 10 20 | 6 30 |
#include <stdio.h>
int main()
{
int a, b;
while (scanf("%d %d", &a, &b) != EOF)
printf("%d\n", a + b);
printf("\n");//打印空行
return 0;
}
A+B for Input-Output Practice (VIII)
H - A+B for Input-Output Practice (VIII)
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
Inputcopy | Outputcopy |
---|---|
3 4 1 2 3 4 5 1 2 3 4 5 3 1 2 3 | 10 15 6 |
#include<stdio.h>
int main()
{
int test,t=0;
scanf("%d",&test);//行数
while(test--)//每执行一次,减少一行
{
int s=0,i;
int n,a[1000];//用数组的方式完成相加
scanf("%d",&n);//需要相加的数字的个数
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
s+=a[i];
}
t++;
if(t>1)
printf("\n");
printf("%d\n",s);
}
return 0;
}
K - 人见人爱A+B
HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱。
这个题目的A和B不是简单的整数,而是两个时间,A和B 都是由3个整数组成,分别表示时分秒,比如,假设A为34 45 56,就表示A所表示的时间是34小时 45分钟 56秒。
Input
输入数据有多行组成,首先是一个整数N,表示测试实例的个数,然后是N行数据,每行有6个整数AH,AM,AS,BH,BM,BS,分别表示时间A和B所对应的时分秒。题目保证所有的数据合法。
Output
对于每个测试实例,输出A+B,每个输出结果也是由时分秒3部分组成,同时也要满足时间的规则(即:分和秒的取值范围在0~59),每个输出占一行,并且所有的部分都可以用32位整数表示。
Sample
Inputcopy | Outputcopy |
---|---|
2 1 2 3 4 5 6 34 45 56 12 23 34 | 5 7 9 47 9 30 |
#include<stdio.h>
int main(){
int n,t,h1,m1,s1,h2,m2,s2,t1,t2;
scanf("%d\n",&n);
while(n--){
scanf("%d%d%d%d%d%d",&h1,&m1,&s1,&h2,&m2,&s2);
t1=h1*3600+m1*60+s1;t2=h2*3600+m2*60+s2;
t=t1+t2;
printf("%d %d %d\n",t/3600,t%3600/60,t%60);
}
return 0;
}
L - 人见人爱A-B
参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法运算。(当然,大家都知道集合的定义,就是同一个集合中不会有两个相同的元素,这里还是提醒大家一下)
呵呵,很简单吧?
Input
每组输入数据占1行,每行数据的开始是2个整数n(0<=n<=100)和m(0<=m<=100),分别表示集合A和集合B的元素个数,然后紧跟着n+m个元素,前面n个元素属于集合A,其余的属于集合B. 每个元素为不超出int范围的整数,元素之间有一个空格隔开.
如果n=0并且m=0表示输入的结束,不做处理。
Output
针对每组数据输出一行数据,表示A-B的结果,如果结果为空集合,则输出“NULL”,否则从小到大输出结果,为了简化问题,每个元素后面跟一个空格.
Sample
Inputcopy | Outputcopy |
---|---|
3 3 1 2 3 1 4 7 3 7 2 5 8 2 3 4 5 6 7 8 0 0 | 2 3 NULL |
#include<stdio.h>
#include<math.h>
const int maxn=100+5;
int main(){
int n,m;
while(scanf("%d%d",&n,&m)&&(n!=0||m!=0)){
int i,j,a[105],b[105];
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=0;i<m;i++) scanf("%d",&b[i]);
int c[105],t=0;
for(i=0;i<n;i++){
int x=0;
for(j=0;j<m;j++)
if(a[i]==b[j]) x++;
if(x==0) {c[t]=a[i];t++;}
}
if(t==0) {printf("NULL\n");continue;}
int k;
for(i=1;i<t;i++)
for(j=0;j<t-i;j++)
if(c[j]>c[j+1]) { k=c[j];c[j]=c[j+1];c[j+1]=k; }
for(i=0;i<t;i++){
printf("%d ",c[i]);
if(i==t-1) printf("\n");
}
}
return 0;
}
M - 人见人爱A^B
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample
Inputcopy | Outputcopy |
---|---|
2 3 12 6 6789 10000 0 0 | 8 984 1 |
#include<stdio.h>
int main(){
int i,n,a,b;
while(scanf("%d%d",&a,&b)!=EOF&&(a!=0||b!=0)){
int k=a;
for(i=1;i<b;i++){
a=a*k;
if(a>1000){
a%=1000;
}
}
printf("%d\n",a);
}
return 0;
}
and so on......