一、A+B for Input-Output Practice (I)
Time Limit: 1000 ms Memory Limit: 65536 KiB
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
Hint
这是一个求两数之和的题目,输入多对用空格分开的两个数a b,输出a+b的和,每一对数据的和占一行。编写代码时需要注意的是,由于没有指出有多少对输入数据,因此我们可以编写如下代码:
//C语言
#include < stdio.h >
int main() //把main函数定义成int类型
{
int a,b;
while(scanf("%d %d",&a, &b) != EOF) // 输入结束时,scanf函数返回值为EOF,即没有数据输入时则退出while循环
printf("%d\n",a+b);
return 0; //返回值为0
}
//或者C++语言
#include < iostream > //注意头文件的使用方法
using namespace std;
int main()
{
int a,b;
while(cin >> a >> b)
cout << a+b << endl;
return 0;
}
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a,&b)!=EOF)
printf("%d\n",a+b);
return 0;
}
二、A+B for Input-Output Practice (III)
Time Limit: 1000 ms Memory Limit: 65536 KiB
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
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a,&b)!=EOF&&a!=0&&b!=0)
printf("%d\n",a+b);
return 0;
}
三、小金问呀问不会问题
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
众所周知,C语言的学习是我们程序设计基础的重点和主要内容。
小金在班里是一个爱学习的好孩子,但是他的编程能力却有点差,不过他坚信自己一定可以进步并追上其他同学。
Input
多组输入。
从键盘读入一个整数n,如果n >= 0代表小金考试进步了,如果n < 0代表小金退步了。
Output
如果小明进步了输出”Yes”,反之输出”No”。输出不包括引号,输入输出各占一行,保证数据合法。
Sample Input
100
-100
Sample Output
Yes
No
#include<stdio.h>
int main()
{
int a;
while(scanf("%d",&a)!=EOF){
if(a>=0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
四、优越数
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
给定3个数,如果有两个数大于他们的平均数则称这组数为优越数。(定义纯属虚构)
Input
输入第一行是一个整数: 表示测试数据的组数。
对于每组测试数据,仅一行3个整数。
Output
对于每组输入数据输出一行,判断它是否为一组优越数,如果是输出“Yes”(输出不包括引号),否则输出“No”。
Sample Input
2
1 2 3
1 4 4
Sample Output
No
Yes
#include<stdio.h>
int main()
{
int n,a,b,c,x;
double ave;
scanf("%d",&n);
while(n-->0)
{
scanf("%d%d%d",&a,&b,&c);
x = 0;
ave = (a+b+c)/3.0;
if(a>ave)
{
x++;
}
if(b>ave)
{
x++;
}
if(c>ave)
{
x++;
}
if(x==2)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
五、分段函数求值
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
有如下分段函数
F(x) = x^2 + 1 当x> 0时;
F(x) = -x 当x<0时;
F(x) = 100.0 当x=0时;
编程根据输入的不同x(x为实数),输出其对应的函数值
Input
多组输入,每组一个实数x。处理到文件结束。
Output
对于每组输入x,输出其对应的F(x),每组一行,结果保留1位小数。
Sample Input
8.00
-5.0
Sample Output
65.0
5.0
#include<stdio.h>
int main()
{
double x;
while(scanf("%lf",&x)!=EOF)
{
if(x>0)
printf("%.1lf\n",x*x+1);
else if(x==0)
printf("100.0\n");
else
printf("%.1lf\n",-x);
}
return 0;
}
六、直角坐标系
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
X是一个喜欢数学的小孩,现在他刚刚学了坐标系。他想知道点(X,Y)在第几象限内。输入数据保证点不在坐标轴及原点上。
Input
多组输入。
每组输入两个整数X,Y,代表点(X,Y),中间用空格隔开。
Output
输出一个整数代表点在第几象限内。
Sample Input
2 3
-2 -3
Sample Output
1
3
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a>0&&b>0)
printf("1\n");
else if(a>0&&b<0)
printf("4\n");
else if(a<0&&b<0)
printf("3\n");
else if(a<0&&b>0)
printf("2\n");
}
return 0;
}
七、计算球体积
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
根据输入的半径值,计算球的体积。
Input
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
Sample Input
1
1.5
Sample Output
4.189
14.137
Hint
#define PI 3.1415927
#include<stdio.h>
#define PI 3.1415927
int main()
{
double a;
while(scanf("%lf",&a)!=EOF)
{
printf("%.3lf\n",4*PI*a*a*a/3); 《换成4/3*PI*a*a*a就不对》
}
return 0;
}
八、洗衣服
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
X是一个勤劳的小孩,总是会帮助大人做家务。现在他想知道对于一根长为L的绳子能晾开多少件宽为W的衣服,显然这些衣服不能相互叠压。
Input
多组输入。
每组输入两个整数L,W。
Output
输出答案。
Sample Input
10 5
10 4
Sample Output
2
2
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
printf("%d\n",a/b);
}
return 0;
}
九、压岁钱
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
SuShan过年要给孩子们发压岁钱喽,由于家里孩子很多,这可急坏了SuShan。你肯定以为她在担心钱不够,那你错了,她可是个有钱人儿,不差钱儿。她担心的是每个人分多少从而保证公平。
SuShan从瑞士银行提出1000000来给孩子们分,由于来的孩子的数目不确定,所以SuShan希望你能帮他计算一下每个孩子给多少钱,从而保证每个孩子得到的都是整数。
Input
输入有多组数据,第一行 T 代表数据的组数。
接下来有 T 行,每行一个整数 N,代表孩子的数目,1<= N <= 10000000。
Output
只有一行。如果能够分给每个孩子相同数目的压岁钱,且都是整数,则输出每个孩子得到的钱数。否则输出No。
Sample Input
3
1
2
3
Sample Output
1000000
500000
No
#include<stdio.h>
int main()
{
int T,a;
scanf("%d",&T);
while(T-->0)
{
scanf("%d",&a);
if(1000000%a==0)
printf("%d\n",1000000/a);
else
printf("No\n");
}
return 0;
}
十、明天是几号?
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
忙碌了一天的 bLue 累得瘫在床上,他想知道明天是几号,你能告诉他吗?
Input
输入数据有多组(数据组数不超过 50000),到 EOF 结束。
每组数据输入一行,包含用空格隔开的 3 个整数,表示今天的日期,分别为年、月、日。
保证输入日期的年份在 1900 到 2035 之间。
Output
对于每组数据,在一行中输出明天的日期,格式为 "y m d",分别表示年、月、日。
Sample Input
2016 12 27
2016 2 29
Sample Output
2016 12 28
2016 3 1
Hint
能被 4 整除且非整百年的,或能被 400 整除的为闰年。
#include<stdio.h>
int main()
{
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
if(c<=27){
printf("%d %d %d\n",a,b,c+1);
}
else if(c==28){
if(b!=2){
printf("%d %d %d\n",a,b,c+1);
}
else
{
if((a%4==0&&a%100!=0)||a%400==0)
printf("%d %d %d\n",a,b,c+1);
else
printf("%d 3 1\n",a);
}
}
else if(c==29)
{
if(b!=2){
printf("%d %d %d\n",a,b,c+1);
}
else
{
printf("%d 3 1\n",a);
}
}
else if(c==30)
{
if(b==4||b==6||b==9||b==11)
{
printf("%d %d 1\n",a,b+1);
}
else{
printf("%d %d %d\n",a,b,c+1);
}
}
else if(c==31)
{
if(b!=12)
{
printf("%d %d 1\n",a,b+1);
}
else{
printf("%d 1 1\n",a+1);
}
}
}
return 0;
}