NBUOJ题解

大一的时候初次解题难免存在一些繁琐和错误,现在将内容站在前人肩膀上重新做整理反思(部分题目前后解法不同,附多解解法)。


//这边部分简单的题目重复,直接对着原来题库写了,一些思路不同的给了不同的解法

1000 整数输入输出练习 
Description
从键盘输入任意两个整数,再向屏幕输出这两个数据。
Input
输入两个整数。
Output
输出这两个整数。以空格间隔。
Sample Input
7 -9
Sample Output
7 -9
HINT
本题的样例代码如下:
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);   
printf("%d %d\n",a,b);
return 0;
}

1001 字符输入输出练习1 
Description
从键盘任意输入一个字符,再输出这个字符。
Input
任意输入一个字符。
Output
输出该字符。
Sample Input
#
Sample Output
#


#include<stdio.h>
int main()
{
	char a;
	scanf("%c",&a);
	printf("%c\n",a);
	return 0;
}
















1002 单组A+B 
Description
从键盘输入任意两个整数a和b,计算并输出a+b的值。
Input
从键盘输入两个整数a和b。
Output
输出这两个数的和
Sample Input
1 2
Sample Output
3


#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	c=a+b;
	printf("%d\n",c);
	return 0;
}















1003 多组A+B(1) 
Description
分别计算多组a+b的值。
Input
输入包含多组测试数据。每行包含一组整数a,b。当输入为0 0 时,测试结束,此时的结果不输出。
Output
对于每一对整数a,b,输出它们的和,并且每行输出一个结果。
Sample Input
1 5
10 20
0 0

#include<stdio.h>
int main()
{
	int a,b,y;
	scanf("%d%d",&a,&b);
	while(a!=0||b!=0)
	{
			y=a+b;
			printf("%d\n",y);
			scanf("%d%d",&a,&b);
	}
	return 0;
}












1004 多组A+B(2) 
Description
分别计算多组a+b的值。
Input
第一行包含一个整数N,表示有N组数据。接下来的N行,每行输入一组a,b数据。
Output
对于每一对整数a,b,输出它们的和,并且每行输出一个结果。
Sample Input
2
1 5
10 20
Sample Output
6
30


#include<stdio.h>
int main()
{
	int a,b,y,i=1,N;
	scanf("%d",&N);
	while(i<=N)
	{
		scanf("%d%d",&a,&b);
			y=a+b;
			printf("%d\n",y);
i++;
	}
	return 0;
}






1005 计算平均分(1) 
Description
输入一个学生的3门课成绩a,b,c,求出该学生的平均分。
Input
输入三个成绩a,b,c。
Output
输出平均值,要求保留1位小数。
Sample Input
60 70 80
Sample Output
70.0


#include<stdio.h>
int main()
{
	double a,b,c,d;
	scanf("%lf%lf%lf",&a,&b,&c);
	d=(a+b+c)/3.0;
	printf("%.1f\n",d);
	return 0;
}















1006 计算月收入 
Description
某小型外贸公司员工月收入的计算方法为:月基本工资加当月提成。从键盘输入某员工某月的基本工资和该月的提成,计算并输出该员工的月收入。
Input
输入两个数分别代表月基本工资和月提成。
Output
计算并输出月收入(保留2位小数)。
Sample Input
3100 1200
Sample Output
4300.00



#include<stdio.h>
int main()
{
	double a,b,c;
	scanf("%lf%lf",&a,&b);
	c=a+b;
	printf("%.2f\n",c);
	return 0;
}













1007 温度转换 
Description
2011夏季,热浪席卷了全球的大部分地方。网上报道美国局部地区的温度达到了100华氏度,而我们国内的温度多在38摄氏度左右。那么38摄氏度和100华氏度到底哪个更热一些呢?请你帮忙编一个程序来解决这一问题。从键盘输入一个华氏温度,求出其对应的摄氏温度。计算公式如下:
c=5*(f-32)/9
c表示摄氏温度,f表示华氏温度。
Input
输入一个华氏温度值。
Output
输出对应的摄氏温度值,结果要求保留2位小数。
Sample Input
100
Sample Output
37.78



#include<stdio.h>
int main()
{
	double c,f;
	scanf("%lf",&f);
	c=5*(f-32)/9;
	printf("%.2f\n",c);
	return 0;
}









1008 求圆周长和圆面积 
Description
从键盘输入一个圆的半径r,计算并输出圆周长和圆面积。
Input
输入一个圆半径r。
Output
按序输出圆周长和圆面积,结果保留两位小数。
Sample Input
41
Sample Output
257.48 5278.34
HINT
圆周率使用3.14



#include<stdio.h>
#define PI 3.14
int main()
{
	double r,c,s;
	scanf("%lf",&r);
	c=2*PI*r;
	s=PI*r*r;
	printf("%.2f %.2f\n",c,s);
	return 0;
}









1009 求圆柱体表面积 
Description
输入圆柱体的底面半径r和高h,计算圆柱体的表面积并输出到屏幕上,保留2位小数。
Input
输入圆柱体的底面半径r和高h。
Output
计算圆柱体的表面积并输出到屏幕上,保留2位小数。
Sample Input
42.1 71.6
Sample Output
30060.92
HINT
圆周率使用3.14



#include<stdio.h>
#define PI 3.14
int main()
{
	double r,h,s;
	scanf("%lf%lf",&r,&h);
	s=2*PI*r*r+2*PI*r*h;
	printf("%.2f\n",s);
	return 0;
}









1010 计算球体的体积 
Description
编写程序计算球体的体积。参考公式v=(4/3)*PI*r*r*r,其中PI表示圆周率。球体的半径r的值由键盘输入,保留2位小数。
Input
输入球体半径r。
Output
计算球体体积并输出到屏幕上,保留2位小数。
Sample Input
96.2
Sample Output
3727293.58
HINT
圆周率使用3.14


#include<stdio.h>
#define PI 3.14
int main()
{
	double r,v;
	scanf("%lf",&r);
	v=(4/3.0)*PI*r*r*r;
	printf("%.2f\n",v);
	return 0;
}










1011 三角形面积 
Description
从键盘上输入三角形的3条边的边长a,b,c(假定3条边长可以构成三角形),求三角形面积并输出到屏幕上。
可利用海伦公式求解:s=sqrt(p*(p-a)*(p-b)*(p-c));其中p=(a+b+c)/2;
Input
输入三条边的边长(假设3条边长可以构成三角形)。
Output
输出三角形面积。保留2位小数。
Sample Input
3 4 5
Sample Output
6.00


#include<stdio.h>
#include<math.h>
int main()
{
	double a,b,c,p,s;
	scanf("%lf%lf%lf",&a,&b,&c);
	p=(a+b+c)/2;
	s=sqrt(p*(p-a)*(p-b)*(p-c));
	printf("%.2f\n",s);
	return 0;
}











1012 判断三角形 
Description
输入三角形的3条边a,b,c,如果能构成一个三角形,则输出面积,否则输出Error。
Input
输入三个数a,b,c(浮点类型)。
Output
如果这三条边能构成一个三角形就计算并输出这个三角形的面积,保留2位小数。如果不能构成三角形就输出Error。
Sample Input
3 1 4
Sample Output
Error


#include<stdio.h>
#include<math.h>
int main()
{
	double a,b,c,p,s;
	scanf("%lf%lf%lf",&a,&b,&c);
	if(a+b>c&&fabs(a-b)<c)
	{
		p=(a+b+c)/2;
	s=sqrt(p*(p-a)*(p-b)*(p-c));
	printf("%.2f\n",s);
	}
	else
		printf("Error\n");
		return 0;
}







1013 两点的距离 
Description
从键盘输入数据表示平面上任意两点。计算并输出这两点之间的距离。保留2位小数。
Input
依次输入x1,y1和x2,y2分别表示平面上的两点。
Output
输出这两点间的距离。保留2位小数。
Sample Input
3.1 4.2 5.0 6.0
Sample Output
2.62



#include<stdio.h>
#include<math.h>
int main()
{
	double x1,x2,y1,y2,l;
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	l=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	printf("%.2f\n",l);
	return 0;
}












1014 数值类型转换 
Description
输入一个双精度数,输出它的整型值。
Input
输入一个双精度数
Output
输出该数的浮点数形式(保留2位小数)和它对应的整型形式。两数之间以空格间隔。
Sample Input
1.22
Sample Output
1.22 1


#include<stdio.h>
#include<math.h>
int main()
{
	double a;
	int b;
	scanf("%lf",&a);
	b=a;
	printf("%.2f %d\n",a,b);
	return 0;
}












1015 两数交换 
Description
从键盘输入两个整数x,y,然后交换它们的顺序并输出。
Input
输入两个整数x,y(以空格间隔)。
Output
首先输出x,y的初始值,然后换行输出交换后的两数。同一行内的数据以空格间隔。
Sample Input
12 23
Sample Output
12 23 
23 12



#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,t;
	scanf("%d%d",&a,&b);
	printf("%d %d\n",a,b);
	t=a;
	a=b;
	b=t;
	printf("%d %d\n",a,b);
	return 0;
}









1016 两数相除 
Description
输入两个浮点数x,y,计算x除以y的值。
Input
输入两个浮点数x,y。
Output
输出运算结果的值,要求保留两位小数。
Sample Input
2 3
Sample Output
0.67


#include<stdio.h>
#include<math.h>
int main()
{
	double x,y,t;
	scanf("%lf%lf",&x,&y);
	t=x/y;
	printf("%.2f\n",t);
	return 0;
}














1017 商和余数 
Description
输入两个整数x,y,计算x除以y的商和余数。
Input
输入两个整数x,y。
Output
输出商和余数。以空格间隔。
Sample Input
65 14
Sample Output
4 9



#include<stdio.h>
#include<math.h>
int main()
{
	int x,y,a,b;
	scanf("%d%d",&x,&y);
	a=x/y;
	b=x%y;
	printf("%d %d\n",a,b);
	return 0;
}












1018 植树问题 
Description
某学校植树节开展植树活动,已知树苗有m株,参加植树的同学有n人(且m>n),请问每位同学平均可以植树几株?还有几株剩余?
Input
输入两个整数m和n,分别表示树苗的数量和学生的人数(m>n)。
Output
输出每位同学平均植树的数量及剩余的树苗数量。
Sample Input
163 32
Sample Output
5 3


#include<stdio.h>
#include<math.h>
int main()
{
int m,n,a,b;
scanf("%d%d",&m,&n);
a=m/n;
b=m%n;
printf("%d %d\n",a,b);
return 0;
}












1019 美元和人民币 
Description
美元越来越贬值了,手上留有太多的美元似乎不是件好事。赶紧算算你的那些美元还值多少人民币吧。假设美元与人民币的汇率是1美元兑换6.5573元人民币,编写程序输入美元的金额,输出能兑换的人民币金额。
Input
输入美元的金额。
Output
输出能兑换的人民币的数值。输出保留2位小数。
Sample Input
100
Sample Output
655.73



#include<stdio.h>
#include<math.h>
int main()
{
	double x,y;
	scanf("%lf",&x);
	y=x*6.5573;
	printf("%.2f\n",y);
	return 0;
}











1020 计算字符的ASCII码 
Description
编写程序,从键盘输入一个字符,输出它的ASCII码值。
Input
输入一个字符。
Output
输出字符对应的十进制ASCII码值。
Sample Input
A
Sample Output
65




#include<stdio.h>
#include<math.h>
int main()
{
	char x;
	scanf("%c",&x);
	printf("%d\n",x);
	return 0;
}













1021 单个字母的小写变大写 
Description
从键盘输入一个小写字母,将其转换成大写字母并输出。。
Input
输入一个小写字母。(假设输入的一定是小写字母)
Output
输出其大写形式。
Sample Input
a
Sample Output
A



#include<stdio.h>
#include<math.h>
int main()
{
	char x,y;
	scanf("%c",&x);
	y=x-32;
	printf("%c\n",y);
	return 0;
}













1022 简单译码 
Description
从键盘输入两个字母,对它们进行译码。如需要将”Hi”译成密码,规则是:用原字母后的第3个字母来代替,如H后面第3个字母是K,i后面第3个字母是l,因此“Hi”应译为“Kl”。
Input
从键盘输入两个字母,分别存放到变量ch1,ch2中。
Output
按上述规则进行译码后输出,输出字母间不加间隔。
Sample Input
Hi
Sample Output
Kl


#include<stdio.h>
int main()
{
char a,b;
scanf("%c%c",&a,&b);
a=a+3;
b=b+3;
printf("%c%c\n",a,b);
return 0;
}












1023 字符加减运算 
Description
编写一个程序,求两个字符之间的加减运算。
Input
连续输入三个字符,其中第一个输入运算符号(+或者-),后两个输入字符。如+ab表示计算字符a与字符b相加的结果。
Output
输出两字符ASCII码值相加减的结果。
Sample Input
-ab
Sample Output
-1


#include<stdio.h>
int main()
{
int a,b,c;
c=getchar();
a=getchar();
b=getchar();
if(c=='-')
{
printf("%d\n",a-b);
}
else if(c=='+')
{
printf("%d\n",a+b);
}
return 0;
}






1024 求多项式值(1) 
Description
求y=2*x^2+x+8的值。其中,x为浮点数,从键盘输入,经过计算后,将y的值输出到屏幕上,保留1位小数。
Input
输入浮点数x的值。
Output
计算并输出y的值,保留1位小数。
Sample Input
1
Sample Output
11.0


#include<stdio.h>
#include<math.h>
int main()
{
double x,y;
scanf("%lf",&x);
y=2*pow(x,2)+x+8;
printf("%.1f\n",y);
return 0;
}













1025 求多项式值(2) 
Description
编程根据输入的x的值,结合数学函数计算多项式y=3*x^4-2*x^3-x^2+10的结果,结果保留1位小数。
Input
输入浮点数x的值。
Output
计算并输出多项式的结果,保留1位小数。
Sample Input
1
Sample Output
10.0
HINT
建议用double



#include<stdio.h>
#include<math.h>
int main()
{
double x,y;
scanf("%lf",&x);
y=3*pow(x,4)-2*pow(x,3)-pow(x,2)+10;
printf("%.1f\n",y);
return 0;
}









1026 居民电费 
Description
某地居民用电是这样计算的,正常使用部分每度0.538元,阶梯部分每度0.03元。某用户家9月份正常部分用电量为x度,阶梯部分y度,请编程计算该用户9月份应该缴纳的电费。从键盘输入x和y,输出应缴纳电费,保留2位小数。
Input
输入x和y的值。
Output
输出应缴纳的电费,保留2位小数。
Sample Input
10 10
Sample Output
5.68


#include<stdio.h>
#include<math.h>
int main()
{
double x,y,m;
scanf("%lf%lf",&x,&y);
m=x*0.538+y*0.03;
printf("%.2f\n",m);
return 0;
}












1027 存款利息(1) 
Description
输入存款金额money、存期year和年利率rate,根据公式计算存款到期时的利息interest(税前)。公式如下: interest=money(1+rate)^year-money
Input
输入存款金额money、存期year和年利率rate。
Output
输出到期时的利息,保留2位小数。
Sample Input
1000 3 0.0415
Sample Output
129.74
HINT
建议用double


#include <stdio.h>
#include <math.h>
int main()
{
double money,year,rate,interest;
scanf("%lf%lf%lf",&money,&year,&rate);
interest=money*pow(1+rate,year)-money;
printf("%.2f\n",interest); 
return 0;
}










1028存款利息(2) 
Description
输入人民币存款年利率I和存款总额S,计算满一年后本息合计并输出。
Input
输入年利率和存款总数。
Output
计算满一年后本息合计,保留两位小数。
Sample Input
0.03 100000
Sample Output
103000.00


#include<stdio.h>
#include<math.h>
int main()
{
double I,S;
scanf("%lf%lf",&I,&S);
S=S*(1+I);
printf("%.2f\n",S);
return 0;
}














1029 三位数的数位分离 
Description
从键盘输入一个任意的3位整数,分别求出其个位、十位和百位上的数字。
Input
输入任意的一个三位整数
Output
依次输出个位、十位、百位上的数字。以空格间隔。
Sample Input
367
Sample Output
7 6 3


#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,d;
scanf("%d",&a);
b=a%10;
c=(a/10)%10;
d=a/100;
printf("%d %d %d\n",b,c,d);
return 0;
}












1030 棋盘上的麦粒 
Description
舍罕是古印度的国王,据说他十分好玩。宰相依达尔为了讨好国王,发明了现今的国际象棋献给国王。国王非常喜欢,决定嘉奖宰相,许诺满足宰相提出的任何要求。宰相指着棋盘要求:“陛下,请您按棋盘的格子赏赐我一点小麦吧,第一个小格赏我1粒麦子,第二个小格赏我2粒,第三个小格赏4粒,以后每一小格都比前一个小格赏的麦子增加一倍,只要把棋盘上全部64个小格按这样的方法得到的麦子都赏赐给我,我就心满意足了”。国王听了宰相这个“小小”的要求,马上同意了。
结果在给宰相麦子时,国王发现他要付出的比自己想象的要多得多,于是进行了计算,结果令他大惊失色。问题是:舍罕王的计算结果是多少粒麦子。
Input
输入一个整数n代表棋盘的格子,该数字大于1且小于等于64。如输入2,则表示有2个格子,第一个格子放1粒,第二个格子放2粒,则2个格子一共需要3粒麦子。
Output
输出n个格子需要的麦粒数。
Sample Input
64
Sample Output
18446744073709551615
HINT
如果麦粒数sum如下定义:
       unsigned __int64 sum;
 
则计算完成后其输出形式为:
       printf("%I64u\n", sum);









#include<stdio.h>
#include<math.h>
int main()
{
	int i,m,a;
	unsigned __int64 s=0;
	scanf("%d",&m);
	for(i=0;i<m;i++)
	{
		a=pow(2,i);
		s+=a;
		}
	printf("%I64u\n",s);
	return 0;
}




























1031 数据逆序显示 
Description
输入一个任意长度的正整数,将该数逆序输出。如,输入正数237,则逆序显示的结果为732。如输入230,则逆序显示的结果为32。
Input
输入一个正整数
Output
该数的逆序显示结果(数字最前面的0不显示,如340反转后。要求输出为43,而不是043)
Sample Input
123
Sample Output
321

#include<stdio.h>
#include<math.h>
int main()
{
	int a,b;
	scanf("%d",&a);
	if(a%10==0)
	a=a/10;
	while(a>0)
	{
		b=a%10;
		printf("%d",b);
		a=a/10;
	}
	printf("\n");
	return 0;
}






1032 各位数字求和 
Description
编写一个程序,输入一个正整数,然后计算组成该数的各位数字的和。如,输入正数237,其各位的数字分别为2,3,7,加起来的和应该为2+3+7=12。
Input
输入一个正整数。
Output
输出各位数字的和
Sample Input
1234
Sample Output
10

#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c=0;
	scanf("%d",&a);
	if(a%10==0)
	a=a/10;
	while(a>0)
	{
		b=a%10;
		c+=b;
		a=a/10;
	}
	printf("%d\n",c);
	return 0;
}







1033 计算最高位数字 
Description
输入一个任意长度的正整数,求出其最高位数字。如,输入237,则最高位数字为2。
Input
输入一个正整数。
Output
输出最高位数字
Sample Input
4756
Sample Output
4

#include<stdio.h>
#include<math.h>
int main()
{
	int a;
	scanf("%d",&a);
	if(a%10==0)
	a=a/10;
	while(!(a>=0&&a<=9))
	{
		a=a/10;
	}
	printf("%d\n",a);
	return 0;
}









1034 任意长度整数的位数 
Description
输入一个任意长度的正整数,求出它是几位数。
Input
输入一个任意长度的正整数。
Output
输出位数
Sample Input
0
Sample Output
1


#include<stdio.h>
#include<math.h>
int main()
{
	int a,i=1;
	scanf("%d",&a);
	while(!(a>=0&&a<=9))
	{
		a=a/10;
		i+=1;
	}
	printf("%d\n",i);
	return 0;
}









1035 求整数的绝对值 
Description
输入一个整数,输出它的绝对值
Input
输入一个整数n
Output
输出该数的绝对值
Sample Input
-2
Sample Output
2


#include<stdio.h>
#include<math.h>
int main()
{
int n,a;
scanf("%d",&n);
a=fabs(n);
printf("%d\n",a);
return 0;
}














1036 符号属性判断 
Description
从键盘输入任意数x,根据其符号属性,输出对应的y值。 
y=-1  (x<0)
y=0   (x=0)
y=1   (x>0)
Input
输入x。
Output
输出y的值
Sample Input
10
Sample Output
1
HINT
x取浮点类型


#include<stdio.h>
#include<math.h>
int main()
{
double x;
int y;
scanf("%lf",&x);
if(x<0)
y=-1;
else if(x==0)
y=0;
else
y=1;
printf("%d\n",y);
return 0;
}

1037 正数负数 
Description
输入一个整数,判断该数是正数还是负数。
Input
输入整数n。
Output
如果该数是正数就输出“positive”,负数就输出“negative”(输出不含双引号)。 
Sample Input
8
Sample Output
positive


#include<stdio.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
if(n>0)
printf("positive\n");
else if(n<0)
printf("negative\n");
return 0;
}












1038 奇数偶数 
Description
输入一个整数,判断该数是奇数还是偶数。
Input
输入整数n。
Output
如果该数是奇数就输出“odd”,偶数就输出“even”(输出不含双引号)。
Sample Input
8
Sample Output
even



#include<stdio.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2==0)
printf("even\n");
else if(n%2==1)
printf("odd\n");
return 0;
}











1039 奇数和与偶数和(1) 
Description
输入正整数n,计算1~n中的奇数和以及偶数和并输出。
Input
输入一个正整数n。
Output
依次输出奇数和以及偶数和,各占一行。
Sample Input
100
Sample Output
2500 
2550

#include<stdio.h>
#include<math.h>
int main()
{
	int n,a=0,b=0,i=1;
	scanf("%d",&n);
	while(i<=n)
	{
		if(i%2==1)
			a+=i;
		else
			b+=i;
		i++;
	}
	printf("%d\n%d\n",a,b);
	return 0;
}







1040 奇数和与偶数和(2) 
Description
输入正整数n,然后依次输入n个正整数,计算其中的奇数和与偶数和并输出。
Input
先输入一个正整数n,然后依次输入n个正整数。
Output
依次输出其中的奇数和以及偶数和,各占一行。
Sample Input
5 1 8 9 6 4
Sample Output
10 
18

#include<stdio.h>
#include<math.h>
int main()
{
	int n,m,a=0,b=0,i=1;
	scanf("%d",&n);
	while(i<=n)
	{
		scanf("%d",&m);
		if(m%2==1)
			a+=m;
		else
			b+=m;
		i++;
	}
	printf("%d\n%d\n",a,b);
	return 0;
}






1041 分段函数(1) 
Description
有一函数: 
y=x     (x<1) 
y=3x-1 (1<=x<10) 
y=4x-2  (x>=10) 
编写程序,输入x,输出y的值。
Input
输入一个任意整数x。
Output
输出函数y的值。
Sample Input
3
Sample Output
8

#include<stdio.h>
#include<math.h>
int main()
{
int x,y;
scanf("%d",&x);
if(x<1)
y=x;
else if(x>=1&&x<10)
y=3*x-1;
else
y=4*x-2;
printf("%d\n",y);
return 0;
}






1042 分段函数(2) 
Description
输入整数x,计算并输出下面分段函数的值(保留两位小数)。 
y=x^2-2     (x>=0) 
y=sqrt(5-x)  (x<0)
Input
输入一个整数x。
Output
输出函数的值。保留2位小数。
Sample Input
3
Sample Output
7.00


#include<stdio.h>
#include<math.h>
int main()
{
int x;
double y;
scanf("%d",&x);
if(x>=0)
y=pow(x,2)-2;
else if(x<0)
y=sqrt(5-x);
printf("%.2f\n",y);
return 0;
}








1043 分段函数(3) 
Description
输入浮点数x,计算并输出下面分段函数y的值(保留两位小数)。 
y=(x+1)^2+2x+1/x     (x<0) 
y=sqrt(x)                  (x>=0)
Input
输入一个浮点数。
Output
输出函数的值。保留2位小数。
Sample Input
10
Sample Output
3.16


#include<stdio.h>
#include<math.h>
int main()
{
double x,y;
scanf("%lf",&x);
if(x<0)
y=(x+1)*(x+1)+2*x+(1/x);
else if(x>=0)
y=sqrt(x);
printf("%.2f\n",y);
return 0;
}









1044 第几象限 
Description
从键盘输入2个整数x、y值表示一个坐标点,判断该坐标点处于第几象限,并输出相应的结果。假设坐标点不会处于x轴和y轴上。
Input
输入x,y值表示一个坐标点。坐标点不会处于x轴和y轴上。
Output
输出对应的象限,用数字1,2,3,4分别对应四个象限。
Sample Input
1 1
Sample Output
1


#include<stdio.h>
#include<math.h>
int main()
{
	double x;
	double y;
	scanf("%lf%lf",&x,&y);
	if(x>0&&y>0)
	    printf("1\n");
	else if(x<0&&y>0)
	    printf("2\n");
	else if(x<0&&y<0)
		printf("3\n");
	else
		printf("4\n");
	return 0;
}






1045 圆内圆外 
Description
有一个半径为10的圆,圆心坐标为(0,0),从键盘输入任意点的坐标(a,b),判断该点在圆内,在圆外,还是恰巧在圆周上。
Input
输入a,b(a,b均为整数)值表示一个坐标点。
Output
输出对应的信息。in表示在圆内,out表示在圆外,on表示在圆周上。
Sample Input
1 1
Sample Output
in


#include<stdio.h>
#include<math.h>
int main()
{
	int a,b;
	double c;
	scanf("%d%d",&a,&b);
c=sqrt(a*a+b*b);
if(c>10)
printf("out\n");
else if(c==10)
printf("on\n");
else
printf("in\n");
return 0;
}







1046 判断英文字母 
Description
编写一个程序,判断输入的一个字符是否是英文字母。
Input
任意输入一个字符。
Output
输出该字符是否属于英文字母的信息(大小写都可以),属于则输出YES,不属于则输出NO。
Sample Input
2
Sample Output
NO

#include<stdio.h>
#include<math.h>
int main()
{
char a;
	scanf("%c",&a);
if(a>='a'&&a<='z'||a>='A'&&a<='Z')
printf("YES\n");
else
printf("NO\n");
return 0;
}











1047 单个字母大小写互换 
Description
从键盘输入一个英文字母,要求编写一个程序,实现字母的大小写转换。如果输入的是小写字母,则输出其大写形式。如果输入的是大写字母,则输出其小写形式。若是其他字符则原样输出。如输入A,则输出a;若输入#,则依然输出#。
Input
任意输入一个英文字母。
Output
输出对应字符的大(小)写字符,(如A对应于a)。
Sample Input
b
Sample Output
B

#include<stdio.h>
int main()
{
	char x,y;
	scanf("%c",&x);
	if(x>='A'&&x<='Z')
	{
		y=x+32;
	printf("%c\n",y);
	}
	else if(x>='a'&&x<='z')
	{
		y=x-32;	
	printf("%c\n",y);
	}
	else
	{
		y=x;
		printf("%c\n",y);
	}
	return 0;
}
1048 ASCII码对应的英文字母 
Description
从键盘输入一个代表ASCII码值的数字(<127),若该数字对应的字符是英文字母,则输出其字母的形式,否则输出数字本身。
Input
输入一个数字(小于127)。
Output
输出该ASCII值对应的英文字母。
Sample Input
98
Sample Output
b


#include<stdio.h>
#include<math.h>
int main()
{
int a;
	scanf("%d",&a);
if(a>='a'&&a<='z'||a>='A'&&a<='Z')
printf("%c\n",a);
else
printf("%d\n",a);
return 0;
}










1049 单个字符判断 
Description
从键盘输入一个字符,判断该字符是否大写字母、小写字母、数字字符或其他字符。分别输出对应的提示信息。
Input
输入一个字符。
Output
如果该字符是大写字母,则输出“upper”;若是小写字母,则输出“lower”;若是数字字符,则输出“digit”;若是其他字符,则输出“other”。(输出不含双引号)。
Sample Input
1
Sample Output
digit


#include<stdio.h>
int main()
{
	char a;
	scanf("%c",&a);
if(a>='A'&&a<='Z')
printf("upper\n");
else if(a>='a'&&a<='z')
printf("lower\n");
else if(a>='0'&&a<='9')
printf("digit\n");
else
printf("other\n");
	return 0;
}






1050 字符个数统计 
Description
统计从键盘输入的一行字符的个数(字符串长度小于等于1000)。输入以换行符结束。
Input
输入一行字符,以换行符作为结束标记。
Output
统计字符的个数并输出。不包括换行符。
Sample Input
Hello Boy.
Sample Output
10



#include<stdio.h>
int main()
{
	char a;
	int i=0;
	scanf("%c",&a);
while(a!='\n')
{
i++;
	scanf("%c",&a);
}
printf("%d\n",i);
	return 0;
}







1051 字母统计 
Description
编写程序:输入一行字符串(字符串长度小于等于1000),统计出其中的英文字母的个数。以输入换行符作为结束。
Input
输入一行字符串,以换行符结束。
Output
输出字母的个数
Sample Input
Hello Mr.007,my name is @#$%
Sample Output
 15


#include<stdio.h>
int main()
{
	char a;
	int i=0;
	scanf("%c",&a);
while(a!='\n')
{
	if(a>='a'&&a<='z'||a>='A'&&a<='Z')
i++;
	scanf("%c",&a);
}
printf("%d\n",i);
	return 0;
}







1052 数字字符统计 
Description
编写程序:输入一行字符串(长度小于等于1000),统计出其中的数字字符的个数。以输入换行字符作为结束。
Input
输入一行字符串,以换行符结束。
Output
输出数字字符的个数
Sample Input
Hello Mr.007,my name is @#$%
Sample Output
 3



#include<stdio.h>
int main()
{
	char a;
	int i=0;
	scanf("%c",&a);
while(a!='\n')
{
	if(a>='0'&&a<='9')
i++;
	scanf("%c",&a);
}
printf("%d\n",i);
	return 0;
}






1053 字符分类统计 
Description
从键盘输入一行字符串(字符串长度小于等于1000),统计出其中的英文字母、空格、数字和其它字符的个数。输入以换行符结束。
Input
输入一行字符串,以换行符作为结束标记。
Output
按字母、数字、空格、其它字符的顺序输出各类字符的统计结果。为0的项目也要输出。用空格隔开(最后一个数字的后面无空格)。
Sample Input
Hello Boy. It is 30 July.
Sample Output
16 2 5 2


#include<stdio.h>
int main()
{
	char e;
	int a=0,b=0,c=0,d=0;
	scanf("%c",&e);
while(e!='\n')
{
	if(e>='a'&&e<='z'||e>='A'&&e<='Z')
		a++;
	else if(e>='0'&&e<='9')
		b++;
	else if(e==' ')
		c++;
		else
			d++;
	scanf("%c",&e);
}
printf("%d %d %d %d\n",a,b,c,d);
	return 0;
}
1054 相邻字符判相等 
Description
输入一行字符串(长度小于等于1000),以换行符结束。判断其中是否存在相邻两个字符相同的情形,若有,则输出该相同的字符并结束程序(只需输出第一种相等的字符即可)。否则输出No。
Input
输入一行字符。
Output
若相邻字符相等则输出该相同的字符,否则输出No。
Sample Input
hello anna
Sample Output
l

#include<stdio.h>
#include<math.h>
#define N 1000
int main()
{
	int i=0,a=0;
	char str[N];
	scanf("%s",str);
	while(str[i]!='\0')
	{
		if(str[i]==str[i+1])
		{printf("%c\n",str[i]);a++;break;}
		i++;
	}
		if(a==0)
			printf("No\n");
	return 0;
}




1055 统计行数 
Description
编写一个程序,要求统计输入文本的行数。
Input
每行输入任意长度的字符串(每一行的字符串的长度小于等于1000),以输入仅由‘@’号构成的行作为结束, @所在的行不计入行数(文本)
Output
输出文本的行数。
Sample Input
Hello world!
I come from China!
I’m a boy!
@
Sample Output
3

#include<stdio.h>
#include<math.h>
#include<string.h>
#define n 1000
int main()
{
	char str[n];
	int i=0,v=0,j;
	gets(str);
	j=strlen(str);
	while(j!=1||str[i]!='@')
	{
		v++;
		gets(str);
		j=strlen(str);	
	}
	printf("%d\n",v);
	return 0;
}

1056 特定字符出现次数 
Description
从键盘输入一个字符串(长度小于等于1000),以换行结束。再输入一个特定字符ch,判断ch在字符串中的出现次数。
Input
从键盘输入一个字符串,以换行结束。再输入一个特定字符ch。
Output
输出ch在字符串中的出现次数。
Sample Input
THIS IS A TEST
I
Sample Output
2

#include<stdio.h>
#include<math.h>
#include<string.h>
#define n 1000
int main()
{
	char str[n],ch;
	int i,j,v=0;
	gets(str);
	j=strlen(str);
	scanf("%c",&ch);
	for(i=0;i<j;i++)
	{
		if(str[i]==ch)
			v++;
	}
	printf("%d\n",v);
	return 0;
}



1057 字符变换 
Description
输入任意一个字符串(长度小于等于1000),将该字符串中的大写英文字母转换成对应的小写英文字母,而将小写英文字母转换成对应的大写英文字母,其余字符不变,然后输出转换后的字符串。
Input
输入一行字符串,以换行结束。
Output
输出改编后的结果。
Sample Input
 I am a student.I am 19.
Sample Output
 i AM A STUDENT.i AM 19.
HINT

#include<stdio.h>
#include<math.h>
#define N 1000
int main()
{
	char str[N];
	int i=0;
	gets(str);
	while(str[i]!='\0')
	{
		if(str[i]>='a'&&str[i]<='z') str[i]-=32;
		else if(str[i]>='A'&&str[i]<='Z') str[i]+=32;
		i++;
	}
	puts(str);
	return 0;
}



1058 成绩合格问题 
Description
输入一个整数表示课程成绩,判断学生成绩是否合格:当分数大于等于60分时,输出合格信息,在60分以下的,输出不合格信息。
Input
输入一个成绩。
Output
如果该数大于等于60,则输出“pass”,否则输出“failure”。(输出不含双引号)。
Sample Input
 61
Sample Output
 pass


#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=60)
printf("pass\n");
else
printf("failure\n");
	return 0;
}











1059 成绩评级1 
Description
对学生成绩(百分制)评等级:80分(含)以上为A等,60~79为B等,小于60分为C等。
Input
输入一个整数形式的百分制的成绩(0~100)。
Output
如果该成绩大于等于80则输出A,在60~79之间则输出B,小于60分则输出C。
Sample Input
 60
Sample Output
 B


#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=80)
printf("A\n");
else if(a>=60&&a<=79)
printf("B\n");
else
printf("C\n");
	return 0;
}









1060 成绩评级2 
Description
在学生成绩管理中,成绩经常需要在百分制与等级制之间进行转换。输入一个表示成绩的百分制分数,将其转换为对应的等级制并输出。 
90分以上 打印 A 
80---89    打印 B 
70---79    打印 C 
60---69    打印 D 
60 以下   打印 E
Input
输入一个整数表示百分制的成绩,保证输入的整数在0到100之内。
Output
输出百分制转换后对应的五级制
Sample Input
95
Sample Output
A


#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>=90)
printf("A\n");
else if(a>=80&&a<=89)
printf("B\n");
else if(a>=70&&a<=79)
printf("C\n");
else if(a>=60&&a<=69)
printf("D\n");
else
printf("E\n");
	return 0;
}
1061 两数求大数  
Description
从键盘输入任意两个整数,求出其中较大数的数值并输出。
Input
输入两个整数。
Output
输出较大数的数值。
Sample Input
18 9
Sample Output
18


#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a<b)
a=b;
printf("%d\n",a);
	return 0;
}













1062 两整数排序 
Description
从键盘输入两个整数x,y,按从小到大的顺序输出它们的值。
Input
输入两个整数x,y。
Output
按从小到大的顺序输出它们的值。数据之间以空格间隔。
Sample Input
20 16
Sample Output
16 20


#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a<b)
printf("%d %d\n",a,b);
else
printf("%d %d\n",b,a);
	return 0;
}












1063 字符间比大小 
Description
请编写一个程序,比较两个不相同字符间的大小(按ASCII码值比大小)。
Input
任意输入两个字符。
Output
按ASCII码值从小到大输出这两个字符的内容。输出字符间以空格间隔。
Sample Input
BA
Sample Output
A B


#include<stdio.h>
int main()
{
char a,b;
scanf("%c%c",&a,&b);
if(a<b)
printf("%c %c\n",a,b);
else
printf("%c %c\n",b,a);
	return 0;
}












1064 三数求大值 
Description
从键盘输入三个整数x,y,z,求出最大数的值。
Input
输入三个整数x,y,z。
Output
输出最大数的值。
Sample Input
20 16 18
Sample Output
20


#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a<b)
{
if(b<c)
printf("%d\n",c);
else
printf("%d\n",b);
}
else
{
if(a<c)
printf("%d\n",c);
if(a>c)
printf("%d\n",a);
}
	return 0;
}


1065 三整数排序 
Description
从键盘输入三个整数x,y,z,按从大到小的顺序输出它们的值。
Input
输入三个整数x,y,z。
Output
按从大到小的顺序输出它们的值。数据之间以空格间隔。
Sample Input
20 16 18
Sample Output
20 18 16
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a<b)
{if(b<c)
printf("%d %d %d\n",c,b,a);
else
if(a<c)
printf("%d %d %d\n",b,c,a);
else
printf("%d %d %d\n",b,a,c);}
else
{if(a>c)
if(b>c)
printf("%d %d %d\n",a,b,c);
else
printf("%d %d %d\n",a,c,b);
else
printf("%d %d %d\n",c,a,b);}
	return 0;
}


1066 鸡兔同笼(1) 
Description
一个笼子里关了鸡和兔子(鸡有2只脚,兔子有4只脚,没有例外)。已知鸡和兔的总数量为n,总腿数为m。输入n和m,依次输出鸡的数目和兔的数目。如果无解,则输出NO answer。
Input
输入整数n和m,分别表示鸡兔的总数量及总腿数。
Output
依次输出鸡的数目和兔的数目。如果无解,则输出NO answer。
Sample Input
5 16 
Sample Output
2 3

#include<stdio.h>
int main()
{
	int n,m,x,y;
	scanf("%d%d",&n,&m);
	x=2*n-0.5*m;
	y=0.5*m-n;
	if(x>=0&&y>=0&&n==x+y)
		printf("%d %d\n",x,y);
    else
		printf("NO answer\n");
    return 0;
}









1067 夏季促销 
Description
商场夏季促销,购物500元以下,不打折;购物500元(含)以上,95折;购物1000元(含)以上,9折;购物3000元(含)以上,85折;购物5000元(含)以上,8折。根据消费金额,确定用户实际需要支付的数目。
Input
输入消费金额。
Output
输出用户实际需要支出的数目,保留两位小数。 
Sample Input
5100 
Sample Output
4080.00


#include<stdio.h>
#include<math.h>
int main()
{
double a;
scanf("%lf",&a);
if(a<500)
printf("%.2f\n",a);
else if(a>=500&&a<1000)
printf("%.2f\n",0.95*a);
else if(a>=1000&&a<3000)
printf("%.2f\n",0.90*a);
else if(a>=3000&&a<5000)
printf("%.2f\n",0.85*a);
else
printf("%.2f\n",0.80*a);
	return 0;
}



1068 公园门票 
Description
某公园门票的票价是每人50元,一次购票满30张,每张可以少收2元。试编写自动计费系统程序。
Input
输入购票的张数
Output
输出用户实际需要支付的金额,保留两位小数。 
Sample Input
30 
Sample Output
1440.00


#include<stdio.h>
#include<math.h>
int main()
{
double a;
scanf("%lfd",&a);
if(a<30)
printf("%.2f\n",a*50);
else
printf("%.2f\n",a*48);
	return 0;
}










1069 飞船飞行情况 
Description
在“神州号”程序中,需要判断飞船飞行状况。当飞船速度继续加大时,飞船将达到第二宇宙、第三宇宙速度。试编写程序,输入不同的飞船速度V,判断它的各种飞行状况,并按要求显示出来。飞船速度( V) 单位(km/s) 
7.91<=V<11.19      则输出1 ,表示飞船绕地球做匀速圆周运动;                       
11.19<=V<16.67    则输出2,表示(飞船离开地球的控制 ,围绕太阳转; 
V>=16.67              则输出3,表示飞船挣脱太阳引力飞出太阳系。
Input
输入一个浮点数表示飞船速度(假设输入速度大于等于7.91)
Output
输出该飞船的飞行情况
Sample Input
10.00
Sample Output
1

#include<stdio.h>
#include<math.h>
int main()
{
double a;
scanf("%lf",&a);
if(a>=7.91&&a<11.19)
printf("1\n");
else if(a>=11.19&&a<16.67)
printf("2\n");
else
printf("3\n");
	return 0;
}





1070 5和7的整倍数(1) 
Description
试编程判断输入的正整数是否既是5又是7的整倍数。若是,则输出yes;否则输出no
Input
输入一个正整数。
Output
如果是5和7的整倍数就输出yes,如果不是就输出no
Sample Input
35
Sample Output
yes

#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
scanf("%d",&a);
b=a%5;
c=a%7;
if(b==0&&c==0)
printf("yes\n");
else
printf("no\n");
	return 0;
}









1071 5和7的整倍数(2) 
Description
输入正整数n,试编程输出n以内能被5和7整除的数。(不包括n)
Input
输入一个整整数n。
Output
输出n以内能被5和7整除的数。以空格间隔。
Sample Input
100
Sample Output
35 70

#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1;
	scanf("%d",&n);
	while(i<n)
	{
		if(i%5==0&&i%7==0)
			printf("%d ",i);
		i++;
	}
	printf("\n");
	return 0;
}








1072 是否闰年 
Description
写一程序判断某一年是否是闰年。
Input
输入一个整数表示年份
Output
判断该年份是否为闰年,如果不是就输出no ,是就输出yes
Sample Input
2000
Sample Output
yes


#include<stdio.h>
#include<math.h>
int main()
{
int a;
scanf("%d",&a);
if(a%4==0&&a%100!=0||a%400==0)
printf("yes\n");
else
printf("no\n");
	return 0;
}











1073 计算某年某月的天数 
Description
计算某年某月的天数。设计一个程序,根据用户输入的年,月,打印出该年的这一个月的天数。如用户输入的信息是2011年的4月,则打印出该月的天数为30。
Input
输入年和月的数值。如2011 2表示2011年的2月份。
Output
输出该月的天数。
Sample Input
2011 2
Sample Output
28
























#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
scanf("%d%d",&a,&b);
switch(b)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
c=31;
break;
case 4:
case 6:
case 9:
case 11:
c=30;
break;
case 2:
if(a%4==0&&a%100!=0||a%400==0)
c=29;
else
c=28;
break;
}
printf("%d\n",c);
return 0;
}








1074 年龄 
Description
编写程序,输入一位学生的生日(年:y0,月:m0,日:d0);并输入当前的日期(年:y1,月:m1,日:d1);输出该生的实足年龄。
Input
输入学生的数据,每行6个整型,用空格隔开,依次代表y0、m0、d0、y1、m1、d1的值。
Output
输出该生的实足年龄。
Sample Input
1990 9 10 2008 5 5
Sample Output
17


#include<stdio.h>
int main()
{
	int a,b,c,d,e,f;
	int N;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	N=d-a;
	if(e<b||b==e&&f<c)
	   N=N-1;
	printf("%d\n",N);
   return 0;
}









1075 求年月日 
Description
输入年份和天数,输出对应的年、月、日。(注意闰年的判断!)
Input
输入两个整数分别代表年份和天数。(假设数据都在有效范围内)
Output
对应的年、月、日
Sample Input
2011 20
Sample Output
2011-1-20



#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&b,&a);
if(b%4==0&&b%100!=0||b%400==0)
{
if(a>=0&&a<=31)
printf("%d-1-%d\n",b,a);
else if(a>31&&a<=60)
printf("%d-2-%d\n",b,a-31);
else if(a>60&&a<=91)
printf("%d-3-%d\n",a,b-60);
else if(a>91&&a<=121)
printf("%d-4-%d\n",b,a-91);
else if(a>121&&a<=152)
printf("%d-5-%d\n",b,a-121);
else if(a>152&&a<=182)
printf("%d-6-%d\n",b,a-152);
else if(a>182&&a<=213)
printf("%d-7-%d\n",b,a-182);
else if(a>213&&a<=244)
printf("%d-8-%d\n",b,a-213);
else if(a>244&&a<=274)
printf("%d-9-%d\n",b,a-244);
else if(a>274&&a<=305)
printf("%d-10-%d\n",b,a-274);
else if(a>305&&a<=335)
printf("%d-11-%d\n",b,a-305);
else
printf("%d-12-%d\n",b,a-335);
}
else
{
if(a>=0&&a<=31)
printf("%d-1-%d\n",b,a);
else if(a>31&&a<=59)
printf("%d-2-%d\n",b,a-31);
else if(a>59&&a<=90)
printf("%d-3-%d\n",b,a-59);
else if(a>90&&a<=120)
printf("%d-4-%d\n",b,a-90);
else if(a>120&&a<=151)
printf("%d-5-%d\n",b,a-120);
else if(a>151&&a<=181)
printf("%d-6-%d\n",b,a-151);
else if(a>181&&a<=212)
printf("%d-7-%d\n",b,a-181);
else if(a>212&&a<=243)
printf("%d-8-%d\n",b,a-212);
else if(a>243&&a<=273)
printf("%d-9-%d\n",b,a-243);
else if(a>273&&a<=304)
printf("%d-10-%d\n",b,a-273);
else if(a>304&&a<=334)
printf("%d-11-%d\n",b,a-304);
else
printf("%d-12-%d\n",b,a-334);
}
   return 0;
}


1076 a^2+b^2 
Description
编程输入整数a和b,若a^2+b^2 大于100,则输出a^2+b^2 百位以上的数字,否则输出a^2+b^2之和。
Input
输入整数a和b。
Output
输出对应结果。
Sample Input
3 5
Sample Output
34

#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	c=pow(a,2)+pow(b,2);
	if(c>100)
		printf("%d\n",c/100);
	else
		printf("%d\n",c);
	return 0;
}










1077 员工薪水(1) 
Description
某公司规定,每周工作40(含)小时内工资是30元/小时,超过40小时后超出部分按1.5倍给付。编写程序,根据输入工作时数计算雇员收入。
Input
输入一个整数表示某一周工作的小时数。
Output
输出员工这一周的薪水
Sample Input
41
Sample Output
1245


#include<stdio.h>
#include<math.h>
int main()
{
	int a;
	scanf("%d",&a);
	if(a<40)
		printf("%d\n",30*a);
	else
		printf("%d\n",1200+(a-40)*45);
	return 0;
}










1078 员工薪水(2) 
Description
某公司规定,销售人员工资由基本工资和销售提成两部分组成,其中基本工资是1500元/月,销售提成规则如下:
销售额小于等于10000元时,按照5%提成;
销售额大于10000元但小于等于50000元时,超出10000部分按照3%提成;
销售额大于50000元时,超出50000部分按照2%提成。
编写程序,根据销售额计算员工收入。
Input
输入一个整数表示销售额
Output
输出员工的薪水,保留2位小数。
Sample Input
9000
Sample Output
1950.00


#include<stdio.h>
#include<math.h>
int main()
{
	int a;
	scanf("%d",&a);
	if(a<=10000)
		printf("%.2f\n",1500+a*0.05);
	else if(a>10000&&a<=50000)
		printf("%.2f\n",2000+(a-10000)*0.03);
	else
		printf("%.2f\n",3200+(a-50000)*0.02);
	return 0;
}




1079 所得税 
Description
编写程序,根据收入计算出个人所得税。个人所得税法规定,每月收入额减除费用3000元后的余额,为应纳税所得额。个人所得税税率表如下:级数     全月应纳税所得额                        税率(%) 
1    小于等于1500元的部分                           5 
2    大于1500元且小于等于4500元的部分       10 
3    大于4500元且小于等于9000元的部分       20 
4    大于9000元且小于等于35000元的部分     25 
5    大于35000元且小于等于55000元的部分   30 
6    大于55000元且小于等于80000元的部分   35 
7   大于80000元的部分                               45
 (注:本表所称全月应纳税所得额是指每月收入额减除费用 3000元后的余额)
Input
输入一个整数表示个人的月收入。
Output
输出应交的税,如果应交税额为零,则直接输出数字0,否则输出需要缴纳的税额并保留2位小数。
Sample Input
9999
Sample Output
874.80














#include<stdio.h>
#include<math.h>
int main()
{
	int a;
	scanf("%d",&a);
	a=a-3000;
	if(a<0)
		printf("0");
	else if(a>0&&a<=1500)
		printf("%.2f\n",a*0.05);
	else if(a>1500&&a<=4500)
		printf("%.2f\n",75+(a-1500)*0.1);
	else if(a>4500&&a<=9000)
		printf("%.2f\n",375+(a-4500)*0.20);
	else if(a>9000&&a<=35000)
		printf("%.2f\n",1275+(a-9000)*0.25);
	else if(a>35000&&a<=55000)
		printf("%.2f\n",7775+(a-35000)*0.3);
	else if(a>55000&&a<=80000)
		printf("%.2f\n",13775+(a-55000)*0.35);
	else
		printf("%.2f\n",22525+(a-80000)*0.45);
	return 0;
}
















1080 求乘客支付的车费 
Description
某城市普通出租车收费标准如下:起步里程小于等于3公里,起步费10元;超起步里程后小于等于10公里的,每公里租费2元;超过10公里以上的部分加收50%的回空补贴费,即每公里租费3元。营运过程中,因路阻及乘客要求临时停车的,每5分钟按1公里租费(租费两元)计收,不足5分钟的按5分钟计,保留到元,计算并输出乘客应支付的车费(元)。
Input
输入行驶里程与等待时间,均为整数。
Output
输出该乘客应支付的车费,保留到元(整数)。
Sample Input
3  0
Sample Output
10
HINT
如行驶里程为0,但等待时间非0,也需要计费。
#include<stdio.h>
int main()
{
	int x,z,y;
	scanf("%d%d",&x,&z);
    if(x<=0)   y=0;
	else if(x<=3)  y=10;
	else if(x<=10)   y=10+2*(x-3);
    else
		y=24+3*(x-10);
    if(z%5!=0)   y=y+(z/5+1)*2;
	else
		y=y+2*(z/5);
	printf("%d\n",y);	
	return 0;
}


1081 一元二次方程 
Description
求方程ax^2+bx+c=0的根。
Input
输入方程系数a、b、c ( 假设b^2 - 4ac>= 0 )。
Output
依次输出方程的根x1、x2(x1>x2)。若只有一个解,则输出x1。(结果保留2位小数)。
Sample Input
 1 3 2
Sample Output
 -1.00 -2.00

#include<stdio.h>
#include<math.h>
int main()
{
	double a,b,c,d,e;
	scanf("%lf%lf%lf",&a,&b,&c);
	if(b*b-4*a*c==0)
	{
		d=-b/(2*a);
		printf("%.2f\n",d);
	}
	else
	{
		d=(-b+sqrt(b*b-4*a*c))/(2*a);
		e=(-b-sqrt(b*b-4*a*c))/(2*a);
		printf("%.2f %.2f\n",d,e);
	}
	return 0;
}





1082 求点的高度 
Description
假设有四个圆塔,圆心座标分别为(2,2) (-2,2) (-2,-2)  (2,-2)。圆塔直径都为1,圆塔高50米,其他都为平地(高度为0)。要求给出任一坐标值(x,y),打印出该点的高度。
Input
输入两个数x,y表示一个点的坐标。
Output
输出该点的高度
Sample Input
-2 2
Sample Output
50
HINT
double

#include<stdio.h>
#include<math.h>
int main()
{
	double a,b,r;
	scanf("%lf%lf",&a,&b);
r=sqrt((fabs(a)-2)*(fabs(a)-2)+(fabs(b)-2)*(fabs(b)-2));
if(r<=0.5)
printf("50\n");
else
printf("0\n");
return 0;
}







1083 1到10的英文单词 
Description
输入1到10之间的任意一个数字,输出相应的英文单词(首字母大写)。如果输入其他数字则输出Error。
Input
输入1~10之间的任意一个数字。
Output
输出相应的英文单词。首字母大写。
Sample Input
 8
Sample Output
 Eight

#include<stdio.h>
#include<math.h>
int main()
{
	int a;
	scanf("%d",&a);
	switch(a)
	{
	case 1:printf("One\n");break;
	case 2:printf("Two\n");break;
	case 3:printf("Three\n");break;
	case 4:printf("Four\n");break;
	case 5:printf("Five\n");break;
	case 6:printf("Six\n");break;
	case 7:printf("Seven\n");break;
	case 8:printf("Eight\n");break;
	case 9:printf("Nine\n");break;
	case 10:printf("Ten\n");break;
	default:printf("Error\n");
	}	
	return 0;
}

1084 四则运算 
Description
输入一个数学表达式,输出运算结果。如输入为3+8,则输出结果11.000000,如输入为7*8,则输出结果为56.000000。(运算符号局限于+、-、*、/四种)
Input
输入形式为a+(-,*,/)b,即一个数字、一个四则运算符号、一个数字。如3+8。
Output
输出运算结果,如11.000000。
Sample Input
 3+8
Sample Output
 11.000000

#include<stdio.h>
#include<math.h>
int main()
{
	char b;
	double a,c,q;
	scanf("%lf%c%lf",&a,&b,&c);
	switch(b)
	{
	case'+':q=a+c;break;
	case'-':q=a-c;break;
	case'*':q=a*c;break;
	case'/':
		if(c!=0)
			q=a/c;break;
	}
	printf("%lf\n",q);	
	return 0;
}



1085 运费计算 
Description
某运输公司对用户按照路程计算每公里运费。路程越远,每公里运费越低。运费标准如下:
路程km               折扣 
s<250              无折扣 
250<=s<500      2% 
500<=s<1000    5% 
1000<=s<2000  8% 
2000<=s<3000  10% 
s>=3000            15% 
假设每公里每吨货物的基本运费为p元,货物重量为w吨,距离为s公里。
Input
输入基本运费p(<10),货物重量w(<1000),距离s(<4000)。
Output
输出实际产生的运费。(输出时保留2位小数)
Sample Input
0.2  100 300
Sample Output
5880.00
















#include<stdio.h>
#include<math.h>
int main()
{
	double p,w,s,q;
	scanf("%lf%lf%lf",&p,&w,&s);
	if(s<250)
	q=p*w*s;
	else if(s>=250&&s<500)
	q=p*w*s*0.98;
	else if(s>=500&&s<1000)
	q=p*w*s*0.95;
	else if(s>=1000&&s<2000)
	q=p*w*s*0.92;
	else if(s>=2000&&s<3000)
	q=p*w*s*0.9;
	else
	q=p*w*s*0.85;
	printf("%.2f\n",q);	
	return 0;
}




















1086 简单数字打印 
Description
编写程序打印数字1,2,3,…,n,要求每个数字占据一行。
Input
输入整数n(n<100)。
Output
输出1,2,3,…,n,要求每个数字占据一行。
Sample Input
5
Sample Output
1
2
3
4
5

#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1;
	scanf("%d",&n);
	while(i<=n)
	{
			printf("%d\n",i);
		i++;
	}
	return 0;
}







1087 字符串输入输出(2) 
Description
输入长度不超过3的字符序列并原样输出。
Input
输入长度不超过3的字符序列。
Output
输出该字符序列。
Sample Input
Cat
Sample Output
Cat

#include<stdio.h>
#include<math.h>
#define N 3
int main()
{
	
	char str[N];
	scanf("%s",str);
	printf("%s",str);
	putchar('\n');
	return 0;
}












1088 字符串输入输出(3) 
Description
输入任意长度的字符串(以换行结束),原样输出.
Input
输入任意长度的字符串(<100个字符)(以换行结束)
Output
将输入的字符串从屏幕上原样输出
Sample Input
 Hello C Language.
Sample Output
 Hello C Language.

#include<stdio.h>
#include<math.h>
#include<string.h>
#define n 100
int main()
{
	char str[n];
	int i,j;
	gets(str);
	j=strlen(str);
	for(i=0;i<j;i++)
	{
		if(i<j-1)
		printf("%c",str[i]);
		else if(i==j-1)
		printf("%c\n",str[i]);
	}
	return 0;
}



1089 不能被3整除的数 
Description
输入正整数n1和n2,试编程输出n1和n2之间不能被3整除的数。每行输出5个数字。(包含n1和n2)
Input
输入正整数n1和n2。
Output
输出n1和n2之间不能被3整除的数。每行最多输出5个数字。每行数字如果满5个的话,则第5个数字后面没有空格,直接换行。
Sample Input
705 769
Sample Output
706 707 709 710 712
713 715 716 718 719
721 722 724 725 727
728 730 731 733 734
736 737 739 740 742
743 745 746 748 749
751 752 754 755 757
758 760 761 763 764
766 767 769















#include<stdio.h>
#include<math.h>
int main()
{
	int i,m,n;
	int count=0;
	scanf("%d%d",&m,&n);
		for(i=m;i<=n;i++)
		{
			if(i%3==0)
		continue;
		else
		{
			count++;
			if(count!=0&&count%5==0||i==n)
				printf("%d\n",i);
			else
					printf("%d ",i);
		}
		}
	return 0;
}



















1090 整数数列求和(1) 
Description
编写程序,要求计算m=1+2+3+4+····+n。
Input
输入一个正整数n(<2000)。
Output
输出对应的m。
Sample Input
10
Sample Output
55


#include<stdio.h>
#include<math.h>
int main()
{
	int m=0,n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		m+=i;
	}
	printf("%d\n",m);
return 0;
}










1091 整数数列求和(2) 
Description
编写程序,计算:m=1-2+3-4+····+(-)n。
Input
输入一个正整数n(<1000)。
Output
输出对应的m。
Sample Input
10
Sample Output
-5


#include<stdio.h>
#include<math.h>
int main()
{
	int m=0,n,i,a;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		a=i;
		if(a%2==0)
		a=-i;
		m+=a;
	}
	printf("%d\n",m);
return 0;
}







1092 整数数列求和(3) 
Description
输入一个整数n,计算s=1+3+5+…+97+n。n是一个奇数(n>1)。
Input
输入一个奇数n(<1000)。
Output
输出s=1+3+…+n的和。
Sample Input
5
Sample Output
9

#include<stdio.h>
#include<math.h>
int main()
{
	int m=0,n,i=1;
	do
	{
	scanf("%d",&n);
	}
	while(n%2==0);
while(i-2!=n)
{
		m+=i;
        i=i+2;
}
	printf("%d\n",m);
return 0;
}






1093 整数数列求和(4) 
Description
输入一个整数n,计算s=1+1+2+1+2+3+1+2+3+4+…+1+2+3+…+n。
Input
输入一个整数n(<100)(假设n为3)。
Output
(若n为3)输出s=1+1+2+1+2+3的和。
Sample Input
3
Sample Output
10

#include<stdio.h>
#include<math.h>
int main()
{
	int m=0,n,i=1,a=0;
	scanf("%d",&n);
for(i=1;i<=n;i++)
{
	a+=i;
		m+=a;
}
	printf("%d\n",m);
return 0;
}










1094 整数数列求和(5) 
Description
输入一个正整数n,计算s=1+2*2+3*3+….n*n。
Input
输入一个正整数n(<100)。
Output
输出s的值。
Sample Input
3
Sample Output
14

#include<stdio.h>
#include<math.h>
int main()
{
	int s=0,n,i,a=0;
	scanf("%d",&n);
for(i=1;i<=n;i++)
{
	a=i*i;
		s+=a;
}
	printf("%d\n",s);
return 0;
}










1095 整数数列求和(6) 
Description
输入一个整数n,计算s=1*2+2*3+3*4+…+n*(n+1)。
Input
输入一个整数n(<100)。
Output
输出计算结果。
Sample Input
3
Sample Output
20


#include<stdio.h>
#include<math.h>
int main()
{
	int s=0,n,i,a=0;
	scanf("%d",&n);
for(i=1;i<=n;i++)
{
	a=i*(i+1);
		s+=a;
}
	printf("%d\n",s);
return 0;
}









1096 求立方和 
Description
编写程序,求sum=1*1*1+2*2*2+3*3*3+4*4*4+5*5*5+····+n*n*n。
Input
输入一个正整数n(n<=60)。
Output
输出对应的sum。
Sample Input
2
Sample Output
9


#include<stdio.h>
#include<math.h>
int main()
{
	int s=0,n,i,a=0;
	scanf("%d",&n);
for(i=1;i<=n;i++)
{
	a=i*i*i;
		s+=a;
}
	printf("%d\n",s);
return 0;
}









1097 整数数列求和(7) 
Description
求s=a+aa+aaa+aaaa+….的值,其中,a是0~9范围内的一个数字。输入n和a,其中n表示累加的项数。例如,当n=5,a=2时,s=2+22+222+2222+22222。
Input
输入整数n和a,均<9。
Output
计算s=a+aa+aaa+aaaa+….的值并输出,其中共有n项进行累加。
Sample Input
 3 2
Sample Output
 246


#include<stdio.h>
#include<math.h>
int main()
{
	int s=0,n,i,a,b=0;
	scanf("%d%d",&n,&a);
for(i=1;i<=n;i++)
{
	b+=pow(10,i-1);
		s+=a*b;
}
	printf("%d\n",s);
return 0;
}








1098 分数数列求和(1) 
Description
输入一个正整数n,计算1+1/2+1/3….的前n项之和,输出时保留6位小数。
Input
输入正整数n(n<100)
Output
输出前n项之和,保留6位小数。
Sample Input
2
Sample Output
1.500000


#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1;
	double a,s=0;
	scanf("%d",&n);
while(i<=n)
{
a=1.0/i;
s+=a;
i=i+1;
}
	printf("%.6f\n",s);
return 0;
}







1099 分数数列求和(2) 
Description
输入一个正整数n,计算1+1/3+1/5….的前n项之和,输出时保留6位小数。
Input
输入正整数n(n<100)
Output
输出前n项之和,保留6位小数。
Sample Input
 2
Sample Output
 1.333333

#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1;
	double a,s=0;
	scanf("%d",&n);
while(i<=(2*n-1))
{
a=1.0/i;
s+=a;
i=i+2;
}
	printf("%.6f\n",s);
return 0;
}








1100 分数数列求和(3) 
Description
输入一个正整数,计算1-1/2+1/4-1/8+1/16……的前n项之和,输出时保留2位小数。
Input
输入正整数n
Output
输出前n项之和,保留2位小数。
Sample Input
5
Sample Output
0.69


#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1,b;
	double a,c,s=0;
	scanf("%d",&n);
while(i<=n)
{
	if(i%2==0)
		b=-1;
		else
		b=1;
		c=pow(2,i-1);
a=b*1.0/c;
s+=a;
i++;
}
	printf("%.6f\n",s);
return 0;
}

1101 分数数列求和(4) 
Description
有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13,……,试编写程序计算此分数序列的前n项之和。
Input
输入正整数n
Output
输出前n项之和,保留6位小数。
Sample Input
5
Sample Output
8.391667

#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1,b=1,c=2,t;
	double a,s=0;
	scanf("%d",&n);
while(i<=n)
{
a=c*1.0/b;
s+=a;
i++;
t=c;
c=b+c;
b=t;
}
printf("%.6f\n",s);
return 0;
}




1102 分数数列求和(5) 
Description
e=1+1/1!+1/2!+...+1/n!,从键盘输入n,计算e的值。
Input
输入一个整数n
Output
输出e的值,保留6位小数。
Sample Input
5
Sample Output
2.716667

#include<stdio.h>
#include<math.h>
int main()
{
	int i,n;
	double a,e=1,b=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		b*=i;
		a=1.0/b;
		e+=a;
	}
	printf("%.6f\n",e);
	return 0;
}







1103 混合数列求和 
Description
有一数列:(1+2+...n)+(1^2+2^2+...+n^2)+(1+1/2+...+1/n) ,从键盘输入一个正整数n,计算该数列的结果。
Input
输入正整数n
Output
输出数列的计算结果,保留2位小数。
Sample Input
5
Sample Output
72.28


#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1;
	double a,b,c,e=0;
	scanf("%d",&n);
while(i<=n)
{
a=i;
b=pow(i,2);
c=1.0/i;
e=e+a+b+c;
i++;
}
printf("%.6f\n",e);
return 0;
}




1104 计算n! 
Description
从键盘输入n,求n!的值并输出
Input
输入正整数n
Output
输出n!的值。
Sample Input
5
Sample Output
120

#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1,a,e=1;
	scanf("%d",&n);
while(i<=n)
{
a=i;
e=e*i;
i++;
}
printf("%d\n",e);
return 0;
}









1105 求阶乘之和 
Description
求1+2!+3!+...+n!的和
Input
输入一个整数n。
Output
输出1+2!+3!+...+n!的值。
Sample Input
5
Sample Output
153

#include<stdio.h>
#include<math.h>
int main()
{
	int n,i=1,a,e=1,b=0;
	scanf("%d",&n);
while(i<=n)
{
a=i;
e=e*i;
b+=e;
i++;
}
printf("%d\n",b);
return 0;
}




1106求点的高度 
假设有四个圆塔,圆心座标分别为(2,2) (-2,2) (-2,-2)  (2,-2)。圆塔直径都为1,圆塔高50米,其他都为平地(高度为0)。要求给出任一坐标值(x,y),打印出该点的高度。
 
Input
输入两个数x,y表示一个点的坐标。
Output
输出该点的高度。
Sample Input
-2 2
Sample Output
50
HINT
double
Source
NBU OJ

#include<stdio.h>
#include<math.h>
int main()
{
double x,y,a,b,c,d;
scanf("%lf%lf",&x,&y);
a=sqrt((x+2)*(x+2)+(y-2)*(y-2));
b=sqrt((x-2)*(x-2)+(y-2)*(y-2));
c=sqrt((x+2)*(x+2)+(y+2)*(y+2));
d=sqrt((x-2)*(x-2)+(y+2)*(y+2));
if(a<=0.5||b<=0.5||c<=0.5||d<=0.5)
printf("50\n");
else printf("0\n")
return 0;
}

1106 是否阶乘之和? 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 643 | Solved : 167 
Description
输入一正整数N,判断其是否可以表示成一个整数阶乘的形式或者几个不同正整数的阶乘之和。

Input
输入一个正整数N。

Output
对应输入,若可以表示,输出YES,否则输出NO

Sample Input
4

Sample Output
NO

HINT
单个整数阶乘的最大值到12!,即479001600。

Source
NBU OJ

#include<stdio.h>
double f(int n)
{
	double result=1;
	int i;
	for(i=1;i<=n;i++)
		result=result*i;
        return result;
}
void main()
{
	int N,j,m=0;
	int a[100];
	scanf("%d",&N);
	for(j=0;j<12;j++)
		a[j]=f(j+1);
	for(j=11;j>=0;j--)
	{if(N==a[j])
	m++;
	else if(N>a[j])
		N=N-a[j];}
	if(m>0)
		printf("YES\n");
	else
		printf("NO\n");
}
1107 一组整数求和(1) 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1329 | Solved : 884 
Description
输入若干整数,计算这些整数的和。

Input
每行首先输入一个整数N(表示共有N个数),接下去分别输入这N个整数。如: 3 2 4 5 表示有3个数需要求和,这3个数分别为2,4,5。

Output
输出这N个数据的和。

Sample Input
4 1 2 3 4

Sample Output
10

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int N,i=1,s=0,n;
	scanf("%d",&N);
	while(i<=N)
	{scanf("%d",&n);
	s=s+n;
	i++;}
	printf("%d\n",s);
}
1108 一组整数求平均 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1783 | Solved : 866 
Description
从键盘输入一些整数,求出它们的平均值。数据的个数事先不确定,在输入过程中以ctrl+z键(EOF)作为输入结束的标记。

Input
输入一些整数,按回车,然后同时按ctrl键和z键,再按回车结束输入。 

Output
输出这若干个数据的和。

Sample Input
4 1 2 3 4
^z

Sample Output
2.80

HINT

Source
NBU OJ
#include <stdio.h>
#include <math.h>
int main()
{
	int a;
    int s=0;
    int m=0;
while (scanf("%d",&a) != EOF)
    {        s=s+a;   
     m++; }      
  printf("%.2f\n",(float)s/m); 
  return 0;
}
1109 多组整数求和 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 862 | Solved : 441 
Description
计算多组整数的和。

Input
输入包含多组测试数据。每组测试数据首先包含一个整数N(表示有N个数),并跟随N个整数 。如3 2 4 5 表示有3个数需要求和,这3个数分别为2,4,5。最后以EOF作为结束标记。

Output
每行输出每组数据的和。

Sample Input
4 1 2 3 4
5 1 2 3 4 5
^z

Sample Output
10
15

HINT

Source
NBU OJ
#include<stdio.h> 
int main() 
{  
	int n,x,i=1,sum=0;     
	while(scanf("%d",&n)!=EOF)  
	{while(i<=n)  
	{scanf("%d",&x);       
	sum=sum+x;    
	i++;}  
	printf("%d\n",sum);  
	i=1,sum=0;
}  
	return 0; 
}
1110 计算总分 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1166 | Solved : 783 
Description
从键盘输入10位同学的成绩,计算他们的总分。

Input
输入10个整数。

Output
输出这10个成绩的总和。

Sample Input
60 70 80 90 70 65 85 95 100 90

Sample Output
805

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int n,s=0,i=1;
	while(i<=10)
	{
		scanf("%d",&n);
		s=s+n;
		i++;
	}
	printf("%d\n",s);
}
1111 平均分及不合格人数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2433 | Solved : 1159 
Description
输入一个正整数n,再输入n个学生的成绩,计算平均分,并统计不及格同学的个数。

Input
输入一个正整数n表示学生的个数,再输入n个学生的成绩。

Output
输出分两行。
第一行输出平均分(保留1位小数)。
第二行输出不及格同学的个数。不及格人数为0时也要输出。

Sample Input
3
90 90 50

Sample Output
76.7
1

HINT
学生成绩可能带小数

Source
NBU OJ
#include<stdio.h>
void main()
{
	double f=0,ave;
	double a[100];
	int i,n,m=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%lf",&a[i]);
	for(i=0;i<n;i++)
	{f=f+a[i];
	if(a[i]<60)
	m++;
	}
ave=f/n;
	printf("%.1f\n",ave);
	printf("%d\n",m);
}
1112 还是平均分 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2819 | Solved : 1098 
Description
从键盘输入若干同学的成绩,计算他们的平均分。当输入负数时结束输入。

Input
输入若干整数,以负数作为结束标记。

Output
计算平均分(不包括负数),输出保留1位小数。

Sample Input
70 80 90 80 60 -9

Sample Output
76.0

HINT

Source
NBU OJ
#include <stdio.h>
int main()
{ 
	float sum=0,n; 
	int i=0; 
	do 
	{  
		  scanf("%f",&n);
  if(n<0) 
	  break;
  sum+=n; 
  i++; }
	while(1);
	printf("%.1f\n",sum/i);
	return 0;
}
1113 正/负数统计 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2069 | Solved : 980 
Description
统计在所输入的N个整数中有多少个正数、多少个负数、多少个零。

Input
先输入一个整数N,接着输入这N个整数。

Output
按顺序输出正数,负数,零的个数。输出各占一行。个数为0的项目也要输出。

Sample Input
20
-5 0 2 6 8 4 2 1 3 6 9 84 0 2 6 -6 -6 -9 63 5

Sample Output
14
4
2

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int n,i=1,N;
	int o=0,z=0,f=0;
	scanf("%d\n",&N);
	while(i<=N)
	{
		scanf("%d",&n);
		if(n>0)
		{z++;}
		else if(n<0)
		{f++;}
		else
		{o++;}
		i++;
	}
	printf("%d\n%d\n%d\n",z,f,o);
}
1114 计算营业额 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1135 | Solved : 753 
Description
编程统计营业员一天的营业额。

Input
输入若干个数据代表交易金额。由于营业员一天完成的交易次数是不确定的,因此最后附加输入一笔0作为交易金额已全部输入结束的标志。

Output
输出一天的营业额。保留2位小数。

Sample Input
100.5 1200 3190 98.9 0

Sample Output
4589.40

HINT

Source
NBU OJ
#include<stdio.h>
int main()
{
int i=0;
double sum=0,x;
scanf("%lf",&x);
    while(x!=0)
{
sum=sum+x; i++;
     scanf("%lf",&x);
   }
    printf("%.2f\n",sum);
     return 0;
}
1115 橘子问题 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2476 | Solved : 851 
Description
已知市场上每个橘子卖0.4元。假设第1天买了2个橘子,从第2天开始,每天买的个数是前一天的两倍,直到买的橘子个数达到不超过N个的最大值。求每天平均花多少钱。

Input
输入整数N,N大于等于2。

Output
输出平均每天花的钱。保留2位小数

Sample Input
5

Sample Output
0.80

HINT

Source
NBU OJ
#include<stdio.h>
#include<math.h>
int main()
{
	double i=1;
	double m=0;
	double N,s;
	scanf("%lf",&N);
	while((pow(2,i+1)-2)<=N)
	{m=m+pow(2,i);
	s=0.4*m/i;
	i++;}
	printf("%.2f\n",s);
	return 0;
}
1116 最后3位数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1362 | Solved : 709 
Description
输入两个整数x,y,计算 x^y,并求出x^y 的最后3位数。

Input
输入整数x和y。

Output
输出x^y 的值以及该数的最后3位数。

Sample Input
11 3

Sample Output
1331 331

HINT

Source
NBU OJ
#include<stdio.h>
#include<math.h>
int main()
{
int x,y,s;
scanf("%d%d",&x,&y);
s=pow(x,y);
printf("%d %d\n",s,s%1000);
return 0;
}
1117 人口问题 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1068 | Solved : 696 
Description
1980年世界人口已达45亿,按年增长率1%计算,问从什么年份开始世界人口突破N亿。(N是一个大于45亿的数)

Input
输入一个实数N,单位是亿。如输入数字46.2则表示46.2亿。

Output
输出对应的年份的值。年份值整数。

Sample Input
45.95

Sample Output
1983

HINT
建议用double

Source
NBU OJ
#include<stdio.h>
#include<math.h>
int main()
{
int n,i=1;
double N,r;
scanf("%lf",&N);
for(i=1;;i++)
{r=45*pow(1.01,i);
if(r>=N)
break;}
n=1980+i;
printf("%d\n",n);
return 0;
}
1118 反弹的小球 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1733 | Solved : 1002 
Description
一个球从100米高度自由落下,每次落地后反弹到原高度的一半再落下,求它在第n次落地时,共经过了多少米,以及第n次反弹的高度。

Input
输入正整数n。

Output
依次输出第n次落地时经过的总路程以及第n次反弹的高度(保留6位小数),中间用一个空格隔开。

Sample Input
10

Sample Output
299.609375 0.097656

HINT

Source
NBU OJ
#include<stdio.h>
#include<math.h>
int main()
{
int n,i=2;
double s=100,h=50;
scanf("%d",&n);
for(i=2;i<=n;i++)
{
s=s+2*h;
h=h/2;}
printf("%.6f %.6f\n",s,h);
return 0;
}
1119 九九乘法表 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2669 | Solved : 992 
Description
输入一个正整数n,打印1~n的乘法表。n小于等于9。

Input
输入正整数n。

Output
输出1~n的乘法表,以4列域宽来输出每一个数字。

Sample Input
5

Sample Output
1
2   4
3   6   9
4   8   12  16
5   10  15  20  25

HINT
用%-4d控制左对齐的输出格式,但是每行最后一个数据直接用"%d\n"来控制输出。

Source
NBU OJ
#include<stdio.h>
void main()
{
	int i,j,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=i;j++)
			if(j<i)
			printf("%-4d",i*j);
			else
			printf("%d\n",i*j);
	}
}
1120 平方表 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1292 | Solved : 853 
Description
编写程序显示平方表。首先从键盘输入一个整数n,然后显示出n行的输出,每行包含一个1~n的数及其平方值(数据间用一个空格隔开)。如从键盘输入4以后将有如下的输出:
1 1
2 4
3 9
4 16

Input
输入一个正整数n(1<=n<=1000)。

Output
输出1~n的数及其平方值。

Sample Input
2

Sample Output
1 1
2 4

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int i,n,m;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		m=i*i;
		printf("%d %d\n",i,m);
	}
}
1121 乘方表 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1871 | Solved : 656 
Description
输入一个正整数n,生成一张2的乘方表,输出2^0到2^n的值。

Input
输入一个正整数n(1<=n<=30)。

Output
输出该数的乘方表,即2^0到2^n的值。

Sample Input
2

Sample Output
1 2 4

HINT
最后一个数据输出后直接换行,不要再加空格。

Source
NBU OJ
#include<stdio.h>
#include<math.h>
void main()
{
	int i,n,m;
	scanf("%d",&n);
	for(i=0;i<=n;i++)
	{
		m=pow(2,i);
		if(i<n)
		printf("%d ",m);
		else
		printf("%d\n",m);
}
}
1122 百灯判熄 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2288 | Solved : 1099 
Description
有M盏灯,编号为1~M,分别由相应的M个开关控制。开始时全部开关朝上(朝上为开,灯亮),然后进行以下操作:编号凡是1的倍数的灯反方向拨一次开关;是2的倍数的灯再反方向拨一次开关;是3的倍数的灯又反方向拨一次开关,......,直到是M的倍数的灯又方向拨一次开关。请从键盘输入一个整数m代表灯的数量,求出最后为熄灭状态的灯(不亮)的数量以及编号并输出。

Input
输入一个整数m(1<=n<=100)。

Output
输出为两行,第一行是熄灭状态的灯的数量;第二行是最后为熄灭状态的灯的编号(每个数据以4列的域宽显示)。

Sample Input
100

Sample Output
10
   1   4   9   16   25   36   49   64   81 100

HINT
输出控制为%4d

Source
NBU OJ
#include<stdio.h>
 int main() 
 {  
	 int j=0,i=1,n; 
scanf("%d",&n);
     while (i*i<=n)
	 {   j++;
	 i++;  }
	 printf("%d\n",j);
	 for (i=1;i<=j;i++)
	 {   
		 printf("%4d",i*i);  }  
	 printf("\n"); 
 }
1123 求cos(x)的值 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1338 | Solved : 820 
Description
输入一个浮点数x,求cos(x)值(用高等数学中的公式cos(x)=1-x^2/2!+x^4/4!-x^8/8!)

Input
输入x的值

Output
输出cosx的值,保留两位小数

Sample Input
1.57

Sample Output
0.02

HINT
用double型变量

Source
NBU OJ
#include<stdio.h>
#include<math.h>
void main()
{
	double x,s,a,b,c,d,e;
	scanf("%lf",&x);
	a=pow(x,2);
	b=pow(x,4);
	c=4*3*2;
	d=pow(x,8);
	e=8*7*6*5*4*3*2;
	s=1-a/2+b/c-d/e;
	printf("%.2f\n",s);
}
1124 斐波那契的兔子问题 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1902 | Solved : 756 
Description
1202年,意大利数学家斐波那契(Fibonacci)出版了他的《计算之书》,在书中提到了一个关于兔子繁殖的问题:如果一对兔子,过一个月之后长成大兔子,到第三个月就可以生下一对兔子并且以后每个月都生下一对兔子,而所生的一对小兔子也同样到一个月之后长成大兔子,到第三个月就可以生下一对小兔并且以后每个月都会生一对。假如兔子都不死,问第n个月的时候兔子的总对数为多少?

Input
输入一个整数n( 0 < n < =50)

Output
输出第n个月兔子的对数

Sample Input
6

Sample Output
8

HINT
数据量会超出int范围,建议用double或长整型

Source
NBU OJ
#include<stdio.h>
 #include<string.h> 
#define ll __int64 
ll a[51]; 
ll fun(int n) 
{ 
	if(n==1||n==2)   
		return 1;  
	if(!a[n])    
		a[n]=fun(n-1)+fun(n-2); 
	return a[n]; }
 int main()
 {  int n; 
 memset(a,0,sizeof(a)); 
 while(scanf("%d",&n)!=EOF) 
 {  
	 printf("%I64d\n",fun(n)); 
 } 
 }
1125 斐波那契数列 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 4700 | Solved : 1205 
Description
输入整数n,输出斐波那契数列的前n项。

Input
输入一个整数n(1<=n<=50)。

Output
输出斐波那契数列的前n项。以空格间隔,但最后一个数据的后面没有空格。

Sample Input
6

Sample Output
1 1 2 3 5 8

HINT
1、斐波那契数列的排列规则为:第1个数和第2个数的值都为1,从第3个数开始,每个数据都等于它前面相邻的两个数据之和。
2、数据范围可能超出int,所以可考虑使用以下定义:
__int64 a; /*64 位整数数据类型,表示介于-2^63 到2^63-1之间的数值*/
则输入格式为 scanf("%I64d",&a);
输出格式为 printf("%I64d ",a);

Source
NBU OJ
#include<stdio.h>
int main()
{	
	int n,i=1;	
	double a=1,b=1;	
	scanf("%d",&n);	
	if(n==1)		
		printf("1");	
	else if(n==2)		
		printf("1 1");	
	else	
	{		
		printf("1 1");	    
		for(i=3;i<=n;i++)		
		{			
			b=a+b;		
			a=b-a;		    
			printf(" %.f",b);	
	}	
}	
	printf("\n");
	return 0;
}
1126 水仙花数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 3025 | Solved : 1166 
Description
输入整数n,求小于n的水仙花数(n<1000)。所谓“水仙花数”是指一个三位正整数ABC,其各位数字的立方和等于该数本身,即
 
例如,370是一个水仙花数,因为
 

Input
输入一个正整数n(n<1000)

Output
输出小于n的所有水仙花数。如果该范围内部不存在水仙花数,则输出No Answer。

Sample Input
400

Sample Output
153
370
371

HINT

Source
NBU OJ
#include<stdio.h>
#include<math.h>
int main()
{
	int i=1,tp=0;
	int x,y,z,n;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{x=i%10;
	y=i/100;
	z=(i/10)%10;
	if(x*x*x+y*y*y+z*z*z==i&&i>=100)
	{printf("%d\n",i);
	tp=1;}
	}
    if(tp==0)
	    printf("No Answer\n");
	return 0}
1127 判断完全数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1674 | Solved : 911 
Description
从键盘输入一个整数n,判断其是否完全数。如果一个正整数恰好等于它所有的真因子(即除了自身以外的因子)之和,则称之为完全数(又称完美数)。如6=1+2+3,6是一个完全数。

Input
输入一个正整数n。

Output
判断该数是否为完全数。是完全数则输出yes,不是完全数则输出no。

Sample Input
6

Sample Output
yes

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int n,m=0,i;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		if(n%i==0)
			m=m+i;}
	if(m==n)
		printf("yes\n");
	else
		printf("no\n");
}
1128 分解质因数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1829 | Solved : 631 
Description
根据数论的知识可知,任何一个合数都可以写成几个质数相乘的形式,这几个质数都叫做这个合数的质因数。例如:24=2×2×2×3。现在从键盘输入一个正整数,请编程输出它的所有质因数。

Input
从键盘输入一个正整数n。

Output
输出该整数的所有质因数。

Sample Input
180

Sample Output
2 2 3 3 5

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{ int n,i;
 scanf("%d",&n);
 for (i=2;i<=n;i++)
 { while(n!=i)
 { if(n%i==0)
 { printf("%d ",i);
 n=n/i; } 
 else break; 
} 
} 
 printf("%d",n);
 printf("\n");
}
1129 统计完全数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1428 | Solved : 261 
Description
编写程序,要求输出a到b之间的所有完全数。所谓完全数是只指其真因子(除自身以外的因子)之和与它本身相等的正整数。如6=1+2+3,6是一个完全数。

Input
输入两个正整数a和b。

Output
输出区间[a,b]之间的所有完全数。每个完全数占一行。

Sample Input
1 10000

Sample Output
6
28
496
8128

HINT

Source
NBU OJ
#include<stdio.h>
#include<math.h>
void main()
{
	int n1,n2,m,i,j;
	scanf("%d%d",&n1,&n2);
	for(i=n1;i<=n2;i++)	
	{	m=0;
		for(j=1;j<=i/2;j++)
		{
			if(i%j==0)
				m=m+j;
		}
		if(m==i)
			printf("%d\n",i);
}
}
1130 判断素数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 3231 | Solved : 1205 
Description
输入一个整数n(n>1),判断其是否为素数。素数的定义为:一个大于1的整数,如果除了1和其自身以外没有其他正因子,则称此数为素数或质数。

Input
输入一个整数n(n>1)。

Output
如果该数是素数就输出yes,如果不是就输出no。

Sample Input
3

Sample Output
yes

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int n,i,count=0;
	scanf("%d",&n);
	for(i=2;i<n;i++)
	{if(n%i==0)
	count++;}
	if(count>=1)
		printf("no\n");
	else
		printf("yes\n");
}
1131 统计素数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2775 | Solved : 889 
Description
判断[ k1,k2]之间有多少个素数(包含k1和k2),并输出这些素数。 ( 1 <= k1 < k2 <= 1000 )

Input
输入两个正整数k1和k2。

Output
输出两行信息,第一行是[k1,k2]之间素数个数,第二行输出所有素数。素数之间用空格分开。

Sample Input
1 10

Sample Output
4
2 3 5 7

HINT
最后一个素数的后面直接换行,不需要再加空格。

Source
NBU OJ
#include<stdio.h>


#include <stdlib.h>

#include <math.h> 
#define MAX 500

 

bool Isprime(int a){

 if (1==a) return 0;    

 for(int i=2;i<=sqrt(a);i++)          

  if(a%i==0)     return 0; 

  return 1;

}

int Numprime(int k1,int k2,int a[]){
 int t,count=0; 

 

 if(k1>k2)


 {

  t=k1;k1=k2;k2=t;
 }

 

 for(int i=k1;i<=k2;i++)  


  if(Isprime(i))  

  {   

   a[count]=i;   

   count++;  

  }

 return count;

}

void main(){ 

 int k1,k2,count=0;

 int prim[MAX]={0};
 scanf("%d %d",&k1,&k2); 

 count=Numprime(k1,k2,prim);

 printf("%d\n",count); 

 for(int i=0;i<count-1;i++)

  printf(“%d”,prim[i]);
printf(“%d\n”,prim[count-1]);
}
1132 最大公约数和最小公倍数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1954 | Solved : 1037 
Description
求两个正整数的最大公约数和最小公倍数。

Input
输入两个正整数。

Output
输出最大公约数与最小公倍数。

Sample Input
10 15

Sample Output
5 30

HINT
输入的两数的大小顺序不定

Source
NBU OJ
#include<stdio.h>
int main()
{
int a,b,num1,num2,temp,y;
scanf("%d%d",&num1,&num2);
if(num1>num2) 
{
temp=num1; num1=num2; num2=temp;
}
a=num1; b=num2;
while(b!=0) 
{
temp=a%b;
a=b;
b=temp;
}
y=num1*num2/a;
printf("%d ",a); 
printf("%d\n",y);
return 0;
}
1133 具有abcd=(ab+cd)^2性质的四位数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 981 | Solved : 546 
Description
求具有abcd=(ab+cd)^2性质的四位数。比如,3025这个数具有一种独特的性质:将它平分为二段,即30和25,使之相加后求平方,即(30+25)^2,恰好等于3025本身。根据输入求所有具有该性质的四位数abcd。

Input
输入数据为K1、K2,表示所求四位数的数据范围在K1和K2之间。(包含K1和K2,且K1和K2都在1000到9999之间,K2>K1)<X2<=9999) span="" <=""></X2<=9999)>

Output
输出所有满足题目要求的四位数,每个输出数据后面换行(\n)。

Sample Input
2000 3500

Sample Output
2025
3025

HINT

Source
NBU OJ
#include<stdio.h>
#include<math.h>
void main()
{
	int k1,k2,i,a,b;
	scanf("%d%d",&k1,&k2);
	for(i=k1;i<=k2;i++)
	{
		a=i/100;
		b=i%100;
		if(i==pow(a+b,2))
			printf("%d\n",i);
	}
}
1134 abc+cba=N的组合 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1290 | Solved : 446 
Description
已知abc+cba=N,其中a,b,c均为一位数,编程求出满足条件的a,b,c所有组合。

Input
输入一个整数N(0<=N<=1998)

Output
输出满足条件的a,b,c的所有组合。组与组之间换行,组内各数据以逗号间隔。如果不存在这样的a,b,c,则输出“No Solution”。(输出不包含引号)

Sample Input
1333

Sample Output
a=4,b=1,c=9
a=5,b=1,c=8
a=6,b=1,c=7
a=7,b=1,c=6
a=8,b=1,c=5
a=9,b=1,c=4

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
int n,a,b,c,m=0;
scanf("%d",&n);
for(a=0;a<=9;a++)
{for(b=0;b<=9;b++)
{for(c=0;c<=9;c++)
{if(a*100+b*10+c+c*100+b*10+a==n)
{printf("a=%d,b=%d,c=%d\n",a,b,c);
m++;}
}
}
}
if(m==0)
printf("No Solution\n");
}
1135 求矩形个数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 324 | Solved : 224 
Description
有一个大的矩形由(M*N)个小的矩形组成。求一共有多少个矩形。
 

Input
输入两个整数,分别代表M,N (0 <= N,M < 100) 。

Output
输出矩形的个数。

Sample Input
2 2

Sample Output
9

HINT

Source
NBU OJ
#include<stdio.h>
int f(int a)
{int s=0,i;
for(i=1;i<=a;i++)
{s=s+i;}
return s;
}
void main()
{
	int m,n,k;
	scanf("%d%d",&m,&n);
    k=f(m)*f(n);
	printf("%d\n",k);
}
1136 蟠桃记 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1054 | Solved : 642 
Description
喜欢西游记的同学肯定都知道悟空偷吃蟠桃的故事,你们一定都觉得这猴子太闹腾了,其实你们是有所不知:悟空是在研究一个数学问题!什么问题呢?他研究的问题是蟠桃一共有多少个?不过,到最后,他还是没能解决这个难题,呵呵^-^ ,你能帮他解决这个问题吗?
当时的情况是这样的:第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩下的一半多一个,到第n天准备吃的时候只剩下一个桃子。聪明的你,请帮悟空算一下,他第一天开始吃的时候桃子一共有多少个呢?

Input
输入一个正整数n(0 < n < 30 ),表示只剩下一个桃子的事情是在第n天发生的。

Output
输出第一天开始吃的时候桃子的总数。

Sample Input
4

Sample Output
22

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int n,s=1;
	scanf("%d",&n);
	for(n;n>1;n--)
		s=2*(s+1);
	printf("%d\n",s);
}
1137 搬砖问题 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1208 | Solved : 506 
Description
某工地需要搬运砖块,已知男搬4,女搬3,两个小孩抬1块。现有N块砖和N个人,要求1次将所有砖搬完,请问需要男、女、小孩各几人?

Input
输入一个正整数N表示人数和需要搬的砖数。

Output
输出所有可能的男、女、小孩的人数。若无解则输出Error。

Sample Input
36

Sample Output
3 3 30

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
int n,a,b,c,m=0;
scanf("%d",&n);
for(a=0;a<=n/4;a++)
{for(b=0;b<=n/3;b++)
{for(c=0;c<=2*n;c=c+2)
{if(4*a+3*b+c/2==n&&a+b+c==n)
{printf("%d %d %d\n",a,b,c);
m++;}
}
}
}
if(m==0)
printf("Error\n");
}
1138 清除行注释 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 762 | Solved : 114 
Description
给出一个C++源程序代码。请将其中的注释去掉。

Input
输入若干行源程序代码(含注释)。注释全部采用行注释的形式,即用双斜杠开头的字符串,后面的内容全部作为注释内容(包含双斜杠)。

Output
输出去掉注释后的代码,其余内容不变。

Sample Input
//======================
// simplest program
//======================
#include<stdio.h>
using namespace std;
//----------------------
int main(){
cout<<”hello world!\n”;
}//---------------------

Sample Output


#include<stdio.h>
using namespace std;

int main(){
cout<<”hello world!\n”;
}

HINT
原题目把注释清掉后还要把空行删掉,那原来的空行也要删掉,因此还要判断每行前后有没有空格,那与原题意就差多了,所以现在数据改了下,真的是“其余内容不变”。

Source
NBU OJ
#include<stdio.h>
void main()
{
	char a[1000];
	int i=0;
	while(gets(a))
	{
       	for(i=0;a[i]!='\0';i++)
		{
		  if(a[i]=='/'&&a[i+1]=='/')
	          break;
		  else
		    printf("%c",a[i]);
	}
		printf("\n");
	}
}
1139 单词译码 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1581 | Solved : 602 
Description
最近网络上又爆出很多关于信息泄露的事情,看来信息时代的保密问题非常关键。怎样才能隐藏你的关键信息呢?作为程序设计的菜鸟一族,你可以先尝试做一些简单的译码工作。对输入的一个任意的单词进行译码输出。译码规律是:用原来字母后面的第4个字母代替原来的字母,并能循环译码。例如,字母A后面第4个字母是E,用E代替A;同理,字母y用c代替。则单词”China”应译为”Glmre”,”Today”应译为”Xshec”。

Input
输入一个单词,长度不超过9。假设输入内容全部都是英文字母,不存在其他字符。

Output
输出译码后的结果。

Sample Input
Helloz

Sample Output
Lippsd

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	char str[10];
	int i=0;
gets(str);
while(str[i]!='\0')
{
	if(str[i]>='A'&&str[i]<='V')
	{str[i]=str[i]+4;i++;}
	if(str[i]>'V'&&str[i]<='Z')
	{str[i]=str[i]-87+65;i++;}
	if(str[i]>='a'&&str[i]<='v')
	{str[i]=str[i]+4;i++;}
	if(str[i]>'v'&&str[i]<='z')
	{str[i]=str[i]-119+97;i++;}
}
puts(str);
}
1140 单位矩阵初始化 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1692 | Solved : 744 
Description
对用作单位矩阵的数组初始化。单位矩阵在主对角线上的值为1,而其他地方的值为0,并且主对角线上的行、列下标是一样的。

Input
输入一个整数n表示矩阵的行数。

Output
输出n*n的单位矩阵。数据之间以空格间隔,每行的最后一个数据后面有空格。

Sample Input
3

Sample Output
1 0 0
0 1 0
0 0 1

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[100][100];
	int i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(i==j)
				a[i][j]=1;
			else 
				a[i][j]=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		printf("%d ",a[i][j]);
		printf("\n");
		}
}
1141 二维数组的输入和输出 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2042 | Solved : 1049 
Description
输入m行n列的二维数组的值,再按行列形式输出。

Input
第一行输入m,n代表行数和列数。接着输入具体的m*n个元素。

Output
按行列形式换行输出。每一个数据后面都有空格,一行输出完毕后换行。

Sample Input
2 5
1 4 6 23 1
1 -5 2 4 6

Sample Output
1 4 6 23 1
1 -5 2 4 6

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[10][10];
	int m,n,i,j;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
		for(i=0;i<m;i++)
		{
			for(j=0;j<n;j++)
				printf("%d ",a[i][j]);
			printf("\n");
		}
}
1142 二维数组求行平均值 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2243 | Solved : 1219 
Description
输入3*3的 二维数组,求每行元素的平均值。

Input
输入3*3个数据。

Output
输出每行的平均值。每个数据各占一行。保留1位小数。

Sample Input
95 68 78
65 77 88
94 82 73

Sample Output
80.3
76.7
83.0

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[3][3];
	int i,j;
	double d=0,b=0,c=0;
	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
		{scanf("%d",&a[i][j]);}
		for(j=0;j<3;j++)
		{d=d+a[0][j];
		b=b+a[1][j];
		c=c+a[2][j];}
		printf("%.1f\n",d*1.0/3);
		printf("%.1f\n",b*1.0/3);
		printf("%.1f\n",c*1.0/3);
		
}
1143 汉诺塔 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 271 | Solved : 164 
Description
汉诺塔问题是这样的:有3根柱子A,B,C,其中A柱上有64个盘子,盘子大小不等,大的在下,小的在上。要求把这64个盘子从A柱移到C柱上,在移动过程中可以借助B柱,每次只允许移动一个盘子,且在移动过程中在三根柱子上都保持大盘在下,小盘在上。从键盘输入一个整数n(n<=64)表示盘子的个数,打印出移动盘子的正确步骤。
 

Input
从键盘输入盘子的个数n。

Output
打印出n个盘子的移动步骤。每一步骤占据一行。

Sample Input
3

Sample Output
a->c
a->b
c->b
a->c
b->a
b->c
a->c

HINT

Source
NBU OJ
#include<stdio.h>
void move(char source,char target)
{
	printf("%c->%c\n",source,target);
}
void hanoi(int n,char a,char b,char c)
{
	if(n==1)move (a,c);
	else
	{
		hanoi(n-1,a,c,b);
		move(a,c);
		hanoi(n-1,b,a,c);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	hanoi(n,'a','b','c');
	return 0;
}
1144 回文数字 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1181 | Solved : 735 
Description
给定一个数字字符串,判断它是否是回文数字。例如: 121, 1221是回文数字, 123不是回文数字。

Input
输入一个数字字符串。

Output
若是回文输出 Yes, 否则输出 No

Sample Input
123321

Sample Output
Yes

HINT

Source
NBU OJ
#include<stdio.h>
#include<string.h>
void main()
{
	int len,t,i,j;
	char str[100];
	gets(str);
	len=strlen(str);
	t=1;
	i=0;
	j=len-1;
	for(;i<j;i++,j--)
	{
		if(str[i]!=str[j])
		{
			t=0;
			break;
		}
	}
	if(t==1)
		printf("Yes\n");
	else
		printf("No\n");
}
1145 回文字符串 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1374 | Solved : 748 
Description
给定一个字符串,长度不超过100,判断它是否是回文串。例如: aba, abcba是回文, abc, xyy 不是回文。

Input
输入一个字符串, 由小写字母组成。

Output
若是回文输出 Yes, 否则输出 No

Sample Input
abcba

Sample Output
Yes

HINT

Source
NBU OJ
#include<stdio.h>
#include<string.h>
void main()
{
	int len,t,i,j;
	char str[100];
	gets(str);
	len=strlen(str);
	t=1;
	i=0;
	j=len-1;
	for(;i<j;i++,j--)
	{
		if(str[i]!=str[j])
		{
			t=0;
			break;
		}
	}
	if(t==1)
		printf("Yes\n");
	else
		printf("No\n");
}
1146 排列组合 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 762 | Solved : 473 
Description
计算从m个不同的数中取n个的取法

Input
从键盘输入m和n。

Output
输出计算结果。

Sample Input
5 3

Sample Output
10

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int m,n,i,j;
	int s1=1,s2=1,s;
	scanf("%d%d",&m,&n);
	for(i=m;i>=m-n+1;i--)
	{s1=s1*i;}
	for(j=1;j<=n;j++)
	{s2=s2*j;}
	s=s1/s2;
	printf("%d\n",s);}
1147 简单评委打分 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1799 | Solved : 1031 
Description
某学生参加项目结题汇报,假设有8位老师作为评委。计算学生最终得分的方法如下:首先去掉一个最高分和一个最低分,然后计算剩余6个分数的平均值,所得结果就是该学生的最后得分。编程实现此功能。

Input
先从键盘输入8个分数。

Output
去掉一个最高分和一个最低分后计算平均得分。保留2位小数

Sample Input
9.33 9.10 8.77 8.90 9.45 8.53 9.08 9.21

Sample Output
9.06

HINT

Source
NBU OJ
#include<stdio.h>
#define N 8
int main()
{
	float a[N],sum=0,ave,min,max;
	int i;
	for(i=0;i<N;i++)
		scanf("%f",&a[i]);
	min=max=a[0];
	for(i=0;i<N;i++)
	{
		if(min>a[i])
			min=a[i];
		if(max<a[i])
			max=a[i];
		sum+=a[i];
	}
	ave=(sum-min-max)/(N-2);
	printf("%.2f\n",ave);
	return 0;
}
1148 数字字符出现频率 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1479 | Solved : 853 
Description
从键盘输入一行文本,统计其中数字字符0~9出现的频率并输出。没有出现的不要显示。

Input
从键盘输入一行文本。以换行符结束。

Output
输出统计结果。每个数字的信息占一行,如“0:2”表示数字字符0出现了2次。

Sample Input
Hello No 007.

Sample Output
0:2
7:1

HINT
输出内容中:
0:2 表示数字字符0出现了2次
7:1 表示数字字符7出现了1次

Source
NBU OJ
#include<stdio.h>
void main()
{
	int su[10]={0};
	int i;
	char ch;
	while(ch!='\n')
	{
		ch=getchar();
		if(ch>=48&&ch<=57)
			su[ch-48]++;
	}
	for(i=0;i<10;i++)
	{
		if(su[i]!=0)
			printf("%d:%d\n",i,su[i]);
}
}
1149 一维数组基本练习 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1995 | Solved : 1171 
Description
已知某学生期中考试4门课程的成绩,请将这4个成绩存放到数组中,然后计算其本次考试的平均成绩并输出。

Input
从键盘输入4个成绩。

Output
输出平均成绩。保留一位小数。

Sample Input
88 91 80 79

Sample Output
84.5

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[4];
	int i;
	double m;
	for(i=0;i<4;i++)
		scanf("%d",&a[i]);
	m=a[0]+a[1]+a[2]+a[3];
		printf("%.1f\n",m/4);
}
1150 文章中字符数统计 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 881 | Solved : 389 
Description
有一篇文章,共有3段文字,每段不超过1000个字符。要求分别统计其中英文大写字母、英文小写字母、数字的个数。

Input
输入3段文字。

Output
输出统计结果,依次显示大写英文字母个数,小写英文字母个数,数字字符个数。

Sample Input
Technology firm Apple has become the most valuable company in the US, with its market capitalisation overtaking that of Exxon Mobil.
Apple had briefly become the largest US firm on Tuesday, before dropping back below the oil giant.
But Apple has now managed to stay in the top spot at the close of Wall Street for the first time.

Sample Output
14 252 0

HINT

Source
NBU OJ

#include<stdio.h>
#include<string.h>
void main()
{
	char ch[1000],ch1[3000],ch2[3000];;
	int i=0,d=0,m=0,s=0,n;
	gets(ch);
	gets(ch1);
	gets(ch2);
	strcat(ch,ch1);
	strcat(ch,ch2);
	n=strlen(ch);
		for(i=0;i<n;i++)
	{
		if(ch[i]>='0'&&ch[i]<='9')
			s++;
		else if(ch[i]>='A'&&ch[i]<='Z')
			d++;
        else if(ch[i]>='a'&&ch[i]<='z')
			m++;
	}
	printf("%d %d %d\n",d,m,s);
}
1151 无序数组的查找 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2509 | Solved : 1099 
Description
已知一维数组中的10个元素各不相同,查找数组中是否存在值为key的数组元素。如果有,输出相应的下标,否则输出not found。已知数组无序排列。

Input
先从键盘输入10个整数。然后再输入一个待查找的数据key。

Output
若存在,则输出该数所在位置的下标值。若不存在则输出"not found"(输出不包含双引号)。

Sample Input
6 70 -9 80 83 54 3 88 10 2
80

Sample Output
3

HINT
数组的下标从0开始

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[10];
	int i,n,m=0;
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	scanf("%d",&n);
	for(i=0;i<10;i++)
		if(n==a[i])
		{printf("%d\n",i);
		m++;}
		if(m<1)
		printf("not found\n");
}
1152 最大值和最小值 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2781 | Solved : 1333 
Description
从键盘输入任意的10个整数,从中找出最大值和最小值并输出。

Input
输入任意的10个整数。

Output
输出这10个数中的最大值和最小值。各占一行。

Sample Input
1 2 5 4 7 8 3 54 13 20

Sample Output
54
1

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[10];
	int i,m,n;
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	m=n=a[0];
	for(i=0;i<10;i++)
	{
		if(m>a[i])
			m=a[i];
		if(n<a[i])
			n=a[i];
	}
	printf("%d\n",n);
	printf("%d\n",m);
}
1153 一维数组的插入 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 3676 | Solved : 469 
Description
数组a中的10个数按升序排列。从键盘输入一个待插入数key,将其插入到数组中,使数组依然保持升序。

Input
先从键盘输入10个按升序排列的整数,然后再输入一个待插入的数据key。

Output
输出插入后的对应结果,要求依然升序排列。每个数据后面都有空格。

Sample Input
1 3 5 7 9 11 13 15 17 19
6

Sample Output
1 3 5 6 7 9 11 13 15 17 19

HINT

Source
NBU OJ
#include<stdio.h>
#define N 11
void main()
{
	int i,j,key;
        int a[N];
	for(i=0;i<N-1;i++)
		scanf("%d",&a[i]);
	scanf("%d",&key);
	for(i=0;i<N-1&&a[i]<key;i++);
	if(i==N-1)
		a[N-1]=key;
	else
	{
		for(j=N-2;j>=i;j--)
		a[j+1]=a[j];
		a[i]=key;
	}
	for(i=0;i<N;i++)
	printf("%d ",a[i]);
	printf("\n");
}
1154 一维数组的删除 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 3409 | Solved : 492 
Description
有5个整型数据存储在数组中,再输入一个数值key,删除数组中第1个等于key的元素,并将剩余的4个数据输出。如果key不是数组中的元素,则显示not found。

Input
先从键盘输入5个整数,然后再输入一个待删除的数据key。

Output
输出删除后的结果,若不存在则输出not found。输出的每个数据后面到底有没有空格呢?其实没有。。

Sample Input
80 65 93 100 81
93

Sample Output
80 65 100 81

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[5];
	int i,j,key;
	for(i=0;i<5;i++)
		scanf("%d",&a[i]);
	scanf("%d",&key);
	for(i=0;i<5&&a[i]!=key;i++);
	if(i==5)
	{
		printf("not found\n");
	}
	else
	{
	for(j=i;j<4;j++)
		a[j]=a[j+1];
	for(i=0;i<3;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[3]);}
}
1155 一维数组逆序显示 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 4664 | Solved : 1350 
Description
从键盘输入10个整数存放在数组中,再逆序显示这10个数。

Input
从键盘输入10个整数。

Output
逆序显示这10个数。数据间以空格间隔,但最后一个数据后面没有空格,直接换行。

Sample Input
6 7 9 0 -6 16 18 -90 19 10

Sample Output
10 19 -90 18 16 -6 0 9 7 6

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[10];
	int i;
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	for(i=9;i>0;i--)
		printf("%d ",a[i]);
	printf("%d\n",a[0]);
}
1156 简单一维数组排序 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 3223 | Solved : 1108 
Description
期末考试结束了,陈老师找到集训队的同学,希望帮忙开发一个成绩排序的系统。这个应该难不倒集训队员的,先做一个内部小测试吧。随意输入10个学生的成绩,按从高到低的序列显示。

Input
输入10个学生的成绩

Output
输出从高到低的排序结果。

Sample Input
90 80 70 60 50 91 72 18 2 0

Sample Output
91 90 80 72 70 60 50 18 2 0

HINT
最后一个数据的后面不需要空格,直接加换行符

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[10];
	int i,j,m,t;
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	for(i=0;i<9;i++)
	{
		m=i;
		for(j=i+1;j<10;j++)
			if(a[j]<a[m])
				m=j;
			if(m!=i)
			{	t=a[i];
			a[i]=a[m];
			a[m]=t;
	}
}
for(i=9;i>0;i--)
printf("%d ",a[i]);
printf("%d\n",a[0]);
}
1157 最高分和最低分 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2258 | Solved : 1183 
Description
已知有10个同学的成绩,求最高分和最低分以及相应分数所在的位置。从键盘输入10个整数存放在数组中,假设这10个数互不相同,且无序排列。请找出其中最大数及它在数组中的下标,以及最小数和下标。

Input
从键盘输入10个整数。

Output
找出其中最大数及它在数组中的下标,以及最小数和下标。各占一行。

Sample Input
60 70 90 50 65 76 88 95 91 80

Sample Output
95 7
50 3

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[10];
	int i,m,n,mc,nc;
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	m=n=a[0];
	for(i=0;i<10;i++)
	{
		if(m>a[i])
		{m=a[i];
		mc=i;}
		if(n<a[i])
		{n=a[i];
		nc=i;}
	}
	printf("%d %d\n",n,nc);
	printf("%d %d\n",m,mc);
}
1158 有序数组的查找 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2096 | Solved : 961 
Description
已知一维数组中的10个元素各不相同,但已按升序排列。查找数组中是否存在值为key的数组元素。如果有,输出相应的下标,否则输出not found。你有什么好方法吗?

Input
先从键盘输入10个升序排列的整数,然后再输入一个待查找的数据key。

Output
输出对应结果。若不存在则输出not found.

Sample Input
6 7 9 10 16 18 20 35 141 150
21

Sample Output
not found

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[10];
	int key,i,j,m=0;
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	scanf("%d",&key);
	for(i=0;i<10;i++)
	if(a[i]==key)
	{j=i;m++;}
	if(m==0)
		printf("not found\n");
	else
		printf("%d\n",j);
}
1159 字母出现频率 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1302 | Solved : 755 
Description
从键盘输入一行文本(小于1000字符),统计其中每个英文字母出现的频率,并输出出现过的英文字母及其次数,未出现过的不需要显示。为了简化问题的复杂度,假设在统计过程中不区分字母的大小写,即'A'与'a'被认为是一种字母。

Input
先从键盘输入一行文本。以换行符结束。

Output
输出统计结果。

Sample Input
Studing C Language

Sample Output
'A':2
'C':1
'D':1
'E':1
'G':3
'I':1
'L':1
'N':2
'S':1
'T':1
'U':2

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
int letter[26]={0};
char ch;
int i;
while((ch=getchar())!='\n')
{
if(ch>='A'&&ch<='Z')
letter[ch-'A']++;
if(ch>='a'&&ch<='z')
letter[ch-'a']++;
}
for(i=0;i<26;i++)
if(letter[i]!=0)
printf("\'%c\':%d\n",'A'+i,letter[i]);
}
1160 二维数组元素加1操作 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1888 | Solved : 825 
Description
从键盘输入数值,构成一个3行4列的二维整型数组,对每个元素执行加1操作,然后输出该数组的内容。

Input
输入3行4列的二维数组。

Output
按行列形式输出操作后的数组。

Sample Input
1 2 3 4
5 6 7 8
9 10 11 12

Sample Output
2 3 4 5 
6 7 8 9 
10 11 12 13 

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[3][4];
	int i,j;
	for(i=0;i<3;i++)
		for(j=0;j<4;j++)
			scanf("%d",&a[i][j]);
		for(i=0;i<3;i++)
			for(j=0;j<4;j++)
			a[i][j]+=1;
		for(i=0;i<3;i++)
		{
			for(j=0;j<4;j++)
				printf("%d ",a[i][j]);
			printf("\n");
		}
}
1161 二维数组的最大值 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1476 | Solved : 856 
Description
有一个3*4的矩阵,要求编程求出其中值最大的那个元素。

Input
从键盘输入12个数字组成一个3*4的矩阵。

Output
输出矩阵中的最大值。

Sample Input
1 2 5 3
5 3 4 2
0 6 9 1

Sample Output
9

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[3][4];
	int i,j,m;
	for(i=0;i<3;i++)
	for(j=0;j<4;j++)
	scanf("%d",&a[i][j]);
		m=a[0][0];
		for(i=0;i<3;i++)
		{
			for(j=0;j<4;j++)
				if(m<a[i][j])
					m=a[i][j];
		}
		printf("%d\n",m);
}
1162 二维数组最大值及位置 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1781 | Solved : 762 
Description
有一个3*4的矩阵,要求编程求出其中值最大的那个元素,以及其所在的行号和列号。(如果最大数有多个,则显示第1个出现的数据的信息)

Input
从键盘输入12个数字组成一个3*4的矩阵。

Output
输出矩阵中最大值,以及其所在的行号和列号。如有多个最大值,则显示第1个出现的。

Sample Input
1 2 9 3
5 3 4 2
0 6 9 1

Sample Output
9 0 2

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int a[3][4];
	int i,j,max,c=0,b=0;
	for(i=0;i<3;i++)
		for(j=0;j<4;j++)
			scanf("%d",&a[i][j]);
		max=a[0][0];
		for(i=0;i<3;i++)
		{	for(j=0;j<4;j++)
		{
			if(max<a[i][j])
			{
				max=a[i][j];
			    c=i;b=j;
			}
		}
		}
				printf("%d %d %d\n",max,c,b);
		
}
1163 一维数组中的相同元素 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1449 | Solved : 540 
Description
在两个长度相等的一维整型数组中寻找相同元素。先输入一个整数n表示数组的长度,接着分别输入两个数组的内容,且两个整型数组均无重复数值,找出两个数组的相同元素。若存在相同元素输出其相同的元素值,否则输出failure。

Input
数组长度n以及两个数组的内容。

Output
两个数组中相同的值。每个数据占据一行。

Sample Input
6
2 5 6 8 7 1
3 4 5 9 2 0

Sample Output
2
5

HINT

Source
NBU OJ
#include<stdio.h>
#define N 100
void main()
{
	int n,i,j,s=0;
	scanf("%d",&n);
	int a[N],b[N];
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		scanf("%d",&b[i]);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(b[j]==a[i])
			{
				s++;
				printf("%d\n",b[j]);
			}
		}
	}
	if(s==0)
		printf("failure\n");
}
1164 对角线元素和 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1684 | Solved : 848 
Description
从键盘输入一个整数n,然后输入n*n个数据建立一个方阵,计算并输出方阵主对角线元素的和。

Input
先输入一个整数n表示方阵的维数。接着输入n*n个数据形成一个方阵

Output
方阵主对角线元素之和。

Sample Input
3
1 2 4
-1 5 6
3 3 9

Sample Output
15

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	int sum=0,n,a[100][100],j=0,i=0;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		for (j=0;j<n;j++)
		   scanf("%d",&a[i][j]);
	}
    for (i=0;i<n;i++)
	{
		  sum+=a[i][i];
	}
	printf("%d\n",sum);}
1165 杨辉三角形 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2083 | Solved : 999 
Description
杨辉三角的历史悠久,是我国古代数学家杨辉揭示二项展开式各项的系数的数字三角形。
从键盘输入一个整数n,输出如下所示的n行的杨辉三角形。下图是n为5时的杨辉三角形。
 

Input
输入一个整数n。(1<=n<=15)。

Output
输出n行的杨辉三角形。

Sample Input
5

Sample Output
1 
1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1 

HINT
每一个数据的后面都有空格。

Source
NBU OJ
#include<stdio.h>
void main()
{
	int i,j,n;
	int a[15][15];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		a[i][i]=1;
		a[i][0]=1;
	}
	for(i=2;i<n;i++)
		for(j=1;j<i;j++)
			a[i][j]=a[i-1][j]+a[i-1][j-1];
		for(i=0;i<n;i++)
		{
			for(j=0;j<=i;j++)
				printf("%d ",a[i][j]);
			printf("\n");
		}
}
1166 字母金字塔 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1497 | Solved : 762 
Description
从键盘输入一个整数n,输出n行的字母金字塔。如下图所示的是一个n为6的字母金字塔。
 

Input
输入一个整数n。

Output
输出n行的字母金字塔。

Sample Input
6

Sample Output
     A
    B B
   C C C
  D D D D
 E E E E E
F F F F F F

HINT
每个字符后面都有空格

Source
NBU OJ
#include<stdio.h>
void py(int n)
{
	int i,j;
for(i=1;i<=n;i++)
{
	for(j=1;j<=n-i;j++)
		printf(" ");
	for(j=1;j<=i;j++)
		printf("%c ",i+64);
	printf("\n");
}
}
int main()
{
	int n;
	scanf("%d",&n);
	py(n);
	return 0;
}


1166 字母金字塔
Description
从键盘输入一个整数n,输出n行的字母金字塔。如下图所示的是一个n为6的字母金字塔。
 
Input
输入一个整数n。
Output
输出n行的字母金字塔。
Sample Input
6
Sample Output
     A
    B B
   C C C
  D D D D
 E E E E E
F F F F F F

HINT
每个字符后面都有空格

#include<stdio.h>
void py(int n)
{
	int i,j;
for(i=1;i<=n;i++)
{
	for(j=1;j<=n-i;j++)
		printf(" ");
	for(j=1;j<=i;j++)
		printf("%c ",i+64);
	printf("\n");
}
}
int main()
{
	int n;
	scanf("%d",&n);
	py(n);
	return 0;
}


1167 susan的货币兑换 
Description
Susan到中国观光旅游,她不太熟悉人民币,因此分别将1角,2角,5角,1元,2元,5元,10元,20元,50元,100元的人民币依次排序号(从1开始排序号),她每天将自己手中不同面值人民币的张数输入iPAD,以计算手头的人民币数额。请你帮她编写一个程序,可以根据她手中的不同面值人民币的张数,计算出对应的人民币数额。
Input
输入人民币序号及张数。每种面值占据一行。如5 20表示序号为5的人民币有20张。当输入序号或张数为负数时结束。
Output
输出对应的人民币数值。保留2位小数。
Sample Input
5 20
8 40
10 10
-1 0

Sample Output
1840.00
 
#include<stdio.h>
void main()
{
	int a,b,i;
	double s=0;
	scanf("%d%d",&a,&b);
	double d[10][10]={{1,0.1},{2,0.2},{3,0.5},{4,1},{5,2},{6,5},{7,10},{8,20},{9,50},{10,100}};
	while (a>=0 && b>=0)
	{
		for (i=0;i<10;i++)
			if (a==d[i][0]) s=s+b*d[i][1];
        scanf("%d%d",&a,&b);
	}
	printf("%.2lf\n",s);
}
1168 查找学生信息 
Description
将n个学生信息录入到数组中,包括学生的学号和期末考试总成绩,查找某学号学生的相应信息。

Input
第一行输入n(n<100),表示有n个学生; 后面n行输入这n个学生的信息,内容分别为学号和分数,接下来一行输入所要查询的学生学号。

Output
输出该学号学生的成绩,如无匹配学号,则输出“No found!”。(输出不包含引号)

Sample Input
4
084110 100
084111 98
084112 97
084113 99
084111

Sample Output
98

#include<stdio.h>
void main()
{
	int a[100],b[100]; 
	int n,i,m,c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%d",&a[i],&b[i]);
	scanf("%d",&m);
	for(i=0;i<n;i++)
	if(m==a[i])
	{printf("%d\n",b[i]);
	c++;}
	if(c==0)
		printf("No found!\n");
}
1169 二维数组行列互换 
Description
将一个二维数组的行和列元素互换,存放到另一个二维数组中。

Input
第一行输入两个整数m和n分别表示二维数组的行数和列数(均小于20)。 
下一行输入该二维数组的各个元素值。

Output
输出行列变换后的数组。

Sample Input
3 4
1 2 5 3
5 3 4 2
0 6 9 1

Sample Output
1 5 0 
2 3 6 
5 4 9 
3 2 1 

HINT
每个数据的后面都有空格
#include <stdio.h>
void main()
{
	int a[20][20];
	int m,n,i,j;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
		for(j=0;j<n;j++)
		{
			for(i=0;i<m;i++)
				printf("%d ",a[i][j]);
			printf("\n");
		}
}
1170 一维数组排序 
Description
从键盘输入n个整数按从小到大的顺序排序。

Input
第一行输入一个正整数n ,第二行输入这n个整数。

Output
输出n个整数排序后的结果(从小到大排序)。

Sample Input
8
8 2 125 31 0 10 -1 2

Sample Output
-1 0 2 2 8 10 31 125

HINT
最后一个数据的后面没有空格,直接换行。数组长度最大可定义到1000。
#include <stdio.h>
void main()
{
	int a[1000];
	int i,n,j,m,t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n-1;i++)
	{
		m=i;
		for(j=i+1;j<n;j++)
			if(a[j]<a[m])
				m=j;
			if(m!=i)
			{
				t=a[i];
				a[i]=a[m];
					a[m]=t;
			}
	}
	for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
}
1171 多个数的最小公倍数 
Description
也许你已经会了求2个数字最小公倍数的方法,但是如果求多个数字的最小公倍数,你又能找到办法吗?

Input
首先输入一个整数n表示有n个数,然后输入这n个整数。(n<=100)

Output
求出n个整数的最小公倍数。

Sample Input
5 3 5 7 11 9

Sample Output
3465

1172 十进制转换成八进制 
Description
输入一个十进制,把这个数转换为8进制的数输出。

Input
输入一个整数。

Output
输出转化后的8进制数,各数字间空一格,最后一个数据后面也有空格,再换行。

Sample Input
57
Sample Output
7 1

#include<stdio.h>
void main()
{ int a[100],i,j,k,b; 
scanf("%d",&b);
 for(i=0;i<100;i++)
	 if(b!=0) 
	 {  j=b%8; 
	 a[i]=j;   
     b=b/8; 
	 }  
	 else 
	 {a[i]=b;
	 break;} 
	 for(k=i-1;k>=0;k--)
		 printf("%d ",a[k]);
	 printf("\n");
 }
1173 进制转换(1)
Description
输入一个十进制正整数,把这个数转换为n进制。

Input
输入两个整数num和n,num表示要转换的数,n表示要转换成的进制。如10 2表示将数字10转换成二进制。(n<10)

Output
输出转化后的进制数,每个数字之后跟一空格。

Sample Input
10 2

Sample Output
1 0 1 0

HINT

Source
NBU OJ

#include<stdio.h>
#include<math.h>
int main()
{    int n,r,i,t,b;
   char a[100];  
   char c[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
   scanf("%d%d",&n,&r);      
   t=n;    t=(int)fabs(t); 
   for(i=0;;i++)    
   {     b=t%r;    
   if(b>=10)      
	   a[i]=c[b-10]; 
   else        
	   a[i]=b+'0';  
   t=(t-b)/r;     
   if(t==0)       
	   break;    
 }    
   if(n<0)  
	   printf("-");   
   for(;i>=0;i--)    
	   printf("%c ",a[i]);  
   printf("\n");   
   return 0; 
}
1174 哥德巴赫猜想 
Description
所谓哥德巴赫猜想是指,任一大于2的偶数都可以写成两个质数之和(严格说来,这是欧拉的等价描述版本)。例如6=3+3,8=3+5,...,18=7+11。迄今为止,这仍然是一个著名的世界难题,被誉为数学王冠上的明珠。试编写程序,验证任一大于2的偶数都能写成两个质数之和。(可能有多种情况,请输出两数差最大的那组)

Input
输入一个大于2的偶数N。

Output
输出两个质数和的形式,小的质数在前,大的质数在后。

Sample Input
16
Sample Output
16=3+13
#include<stdio.h>
int is_prime(int n)
{
    int i;
    if ( n <= 1 ) return 0;
    for( i=2; i<=n/2 ; i++ )
         if ( n%i==0 ) return 0;
    return 1;
}
int main()
{
int n=0,i;
do{
scanf("%d",&n );getchar();
}while( n<2 && n%2 );
for( i=2;i<=n/2;i++ )
if ( is_prime(i) && is_prime(n-i) )
{
printf("%d=%d+%d\n" , n,i,n-i );
break;
}
return 0;
}
1175 查找最大元素 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1163 | Solved : 606 
Description
对于输入的字符串,查找其中的AscII码最大字母,在该字母后面插入字符串"(max)”。不包括引号。

Input
输入一行长度不超过100的字符串,字符串仅由大小写字母构成。

Output
输出一行字符串,输出的结果是插入字符串"(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入"(max)"。

Sample Input
abcdefgfedcba

Sample Output
abcdefg(max)fedcba

#include <stdio.h>
void main()
{
	int i,mk;
	char *p,maxc,str[100]={0};
	gets(str);
	for (i=0;str[i]!='\0';i++)
	{
		if (i==0||maxc<str[i])
		{
			maxc=str[i];
			mk=i;
		}
	}
	p=str;
	while (*p!=NULL)
	{
		if(*p==maxc)
			printf("%c(max)",*p++);	
		else
			printf("%c",*p++);		
	}
	printf("\n");
}
1176 统计单词数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1397 | Solved : 484 
Description
擎天柱最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里单词的总数。下面你的任务是帮助擎天柱解决这个问题。

Input
输入一行字符表示一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到换行符时表示输入结束,文章最多由1000个字符组成。

Output
输出一个整数,代表一篇文章里单词的总数。

Sample Input
you are my friend

Sample Output
4
#include <stdio.h>
#include <string.h>
int main()
{
int i,n=0;
char ch;
char str[1000];
gets(str);
for(i=0, ch=' '; str[i]!='\0'; i++)
{
    if (str[i]==' ' && ch!=' ') 
       n++;
    ch = str[i];

}
if (ch==' ')
   n = n-1;
printf("%d\n",n+1);
  return 0;
}
1177 交换最小数 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 780 | Solved : 365 
Description
输入n(n<100)个数,找出其中最小的数,将它与最前面的数交换后输出这些数,若最小的数有多个只交换最前面的那个。

Input
先输入一个整数n,表示这个测试实例的数值的个数,跟着就是输入n个整数。

Output
输出交换后的数列。

Sample Input
5 5 4 3 2 1

Sample Output
1 4 3 2 5
#include<stdio.h>
void main()
{
	int a[100];
	int n,i,min,t,m;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	min=a[0];
	for(i=0;i<n;i++)
		if(a[i]<min)
		{min=a[i];
		m=i;
		}
     t=a[0];a[0]=a[m];a[m]=t;
		for(i=0;i<n-1;i++)
			printf("%d ",a[i]);
		printf("%d\n",a[n-1]);
}
1178 寻找重复数字
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 831 | Solved : 266
Description
输入n(n<100)个整数,不排序直接查找并输出所有重复的数字。

Input
先输入一个整数n,表示这个测试实例的数值的个数,跟着输入这n个整数,每个整数都不大于100。

Output
如果存在有重复的数字则依次输出,数字之间用空格间隔,如果不存在重复的数字,则输出-1。

Sample Input
7 5 4 3 2 1 2 4

Sample Output
4 2

HINT

Source
NBU OJ

#include<stdio.h>
#define M 100
int main()
{
	int n,a[M],b[M]={0},c[M],i,j,count=0;   
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n-1;i++)
		for(j=i+1;j<n;j++)
		if(a[j]==a[i])
			{	b[j]=1;	       
				if(b[i]==0)         
                  {	
					c[count]=a[i];
					count++;break;                                                                      
				}
			} 
	if(count==0)
		printf("-1\n");
	else
	{
		for(i=0;i<count-1;i++)
			printf("%d ",c[i]);
		printf("%d\n",c[count-1]);
	}
	return 0;
}
1179 评委打分(2) 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1222 | Solved : 533 
Description
输入n(n<=1000)个实数存放在一维数组中,输出他们除去一个最高分和一个最低分(如果有多个只要去一个)后剩下数的平均数。

Input
输入一个整数n,表示这个测试实例的数值的个数,跟着输入这n个实数。

Output
输出除去最大数和最小数后,剩下的数据的平均数,结果保留2位小数。

Sample Input
7 1 2 3 4 5 6 7

Sample Output
4.00
#include<stdio.h>
void main()
{int n,i=2;
float s,j,k,a,q;
 scanf("%d",&n);
 scanf("%f%f",&j,&k);
 s=j+k;
 if(j<k) {a=j;j=k;k=a;}
 else {j=j;k=k;}
while(i<n)
{scanf("%f",&q);
 if(j<q)
 {j=q;
  k=k;
 }
 if(k>q)
 {j=j;
  k=q;
 }
 s=s+q;
 i++;
}

    printf("%.2f\n",(s-j-k)/(n-2));
}
1180 魔方阵 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 168 | Solved : 76 
Description
输出魔方阵,所谓魔方阵就是指这样的方阵,它的每一行每一列和对角线之和都相等,例如,三阶魔方阵为
8 1 6 
3 5 7 
4 9 2
 要求输出由1—n^2之间的自然数构成的魔方阵。

Input
输入该方阵的阶数n(n<=15且n为奇数)。

Output
输出该n阶魔方阵,每个数字之间用空格间隔

Sample Input
3

Sample Output
8 1 6
3 5 7
4 9 2

HINT
由于魔方阵的填法有很多种,这里给出一种填法: 
1.将1放在第一行的最中央。 
2.接下来的每个数字都放在前一个数字的右上方。如果右上方被占,则放在前一个数字的下面。
请按照这种方法输出对应的魔方阵! 
#include<stdio.h>
void main()
{
	int a[50][50]={0};
	int i,j,v,n;
	scanf("%d",&n);
	i=0;j=n/2;
	a[i][j]=1;
	for(v=2;v<=n*n;v++)
	{
		if(a[(i-1+n)%n][(j+1)%n]==0)
		{
			i=(i-1+n)%n;
			j=(j+1)%n;
		}
		else
			i=(i+1)%n;
		a[i][j]=v;
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n-1;j++)
			printf("%d ",a[i][j]);
			printf("%d\n",a[i][n-1]);
	}
}
1181 二维数组的鞍点 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1032 | Solved : 457 
Description
找出一个2维数组矩阵的鞍点,即该位置上的元素在该行中最大,在该列中最小,可能不存在鞍点,如果存在多个,输出最小的那个!

Input
输入 n,m表示二维矩阵的行数和列数,然后根据行列数输入n*m个数据构成一个二维矩阵。

Output
如果存在鞍点,则输出该鞍点的值,如果不存在则输出not exist。

Sample Input
4 5
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20

Sample Output
5

#include <stdio.h>
int main()
{ int a[100][100],row,col; 
int i,j,k,max,maxj,flag1=1,flag2; 
scanf("%d%d",&row,&col); for(i=0;i<row;i++)
 for(j=0;j<col;j++) 
	 scanf("%d",&a[i][j]); 
 flag2=0; for(i=0;i<row;i++)
 { max=a[i][0];maxj=0;
 for(j=0;j<col;j++)if(max<a[i][j])
 { max=a[i][j];
 maxj=j;}
 for(k=0,flag1=1;k<row&&flag1;k++)
	 if(max>a[k][maxj])
		 flag1=0;if(flag1)
	 { printf("%d\n",max); flag2=1;} }
 if(flag2==0) 
	 printf("not exist\n");}

1182 字符串长度 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1548 | Solved : 744 
Description
输入一个字符串,计算其有效长度。输出字符串长度及字符串内容。请不要使用strlen库函数。

Input
输入1个字符串,以换行符结束。字符串长度不会超过100。

Output
输出有效长度及字符串内容。以空格间隔。
Sample Input
string

Sample Output
6 string

#include <stdio.h>
void main()
{
char c[100];
int i;
gets(c);
for(i=0;c[i]!='\0';i++);
printf("%d %s\n",i,c);
}
1183 连接字符串 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2424 | Solved : 890 
Description
连接2个字符串(长度都不超过100),不要用strcat函数。

Input
输入2个字符串,每个字符串以换行符结束。

Output
输出连接好的字符串。

Sample Input
Country
side

Sample Output
Countryside

#include <stdio.h>
#include<string.h>
void main()
{
char c1[200],c2[100];
int i=0,j=0;
gets(c1);
gets(c2);
while(c1[i]!='\0')i++;
while(c2[j]!='\0')
{
	c1[i]=c2[j];
	i++;
	j++;
}
c1[i]='\0';
puts(c1);
}
1184 姓名排序 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 706 | Solved : 475 
Description
输入两个人的姓名,按字典顺序进行输出。

Input
输入2个字符串,每个字符串以换行符结束(每个名字不超过10个字符,中间无空格)。

Output
按字典顺序排序并输出。各占一行。

Sample Input
Susan
Anney

Sample Output
Anney
Susan

#include<stdio.h>
#include<string.h>
void main()
{
	char str1[20],str2[20];
	gets(str1);
	gets(str2);
	if(strcmp(str1,str2)<0||strcmp(str1,str2)==0)
	{
		puts(str1);
		puts(str2);
	}
	else
	{	puts(str2);
	puts(str1);}
}

1185 城市名排序
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 1075 | Solved : 457
Description
从键盘输入n个城市名,进行升序排序并输出。

Input
第一行输入一个整数n,表示有n个城市,n不超过100。
接着输入n个字符串,每个字符串代表一个城市名,一个字符串内部不包含空格,字符串长度不超过100。

Output
输出排序后的城市名字。每个城市名占据一行。

Sample Input
10
nignbo
hangzhou
quzhou
fuyang
shaoxing
ninghai
lishui
weinan
fujian
guangzhou

Sample Output
fujian
fuyang
guangzhou
hangzhou
lishui
ningbo
ninghai
quzhou
shaoxing
weinan

HINT

Source
NBU OJ

#include<stdio.h>
#include<string.h>
main()
{
int n,i,j,min;
char s[100][100],*p[100],*t;
scanf("%d",&n);
getchar();
for(i=0;i<n;i++)
{
gets(s[i]);
p[i]=s[i];
}
for(i=0;i<n-1;i++)
{
min=i;
for(j=i+1;j<n;j++)
if(strcmp(p[i],p[j])>0)
{t=p[i];p[i]=p[j];p[j]=t;}
}
for(i=0;i<n;i++)
printf("%s\n",p[i]);
}

1186 电文密码 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 636 | Solved : 375 
Description
有一行电文,已经按下面的规律译成密码 
A—>Z   a—>z 
B—>Y  b—>y 
C—>X c—>x
 即把第一个字母变成第26个字母,第i个字母变成第(26-i+1)个字母,非字母的字符保持不变。

Input
输入已经按上述方式加密的电文(电文的长度不超过1000),要求输出其原文,其中可能有空格。

Output
输出电文的原文。

Sample Input
R droo erhrg Xsrmz mvcg dvvp.

Sample Output
I will visit China next week.
#include<stdio.h>
#include<string.h>
void main()
{
 char arr[1000];
 int len,i;
 gets(arr);
 len=strlen(arr);
 for(i=0;i<len;i++)
 {
  if(arr[i]>='a'&&arr[i]<='z')
  {
   arr[i]='a'+'z'-arr[i];
  }
  else if(arr[i]>='A'&&arr[i]<='Z')
  {
   arr[i] ='A'+'Z'-arr[i];
  }
 }
 puts(arr);
}
1187 数字提取
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 892 | Solved : 515
Description
CoCo和Tom比谁的记性好,这次的比试项目是数字提取。由裁判Mary读出一串字符,CoCo和Tom快速将该字符串中出现过的数字按顺序提取出来并记录在纸上,由Mary来比对谁写的正确。你能编写一个程序,模拟这个数字提取的过程吗?

Input
从键盘输入一个字符串,以换行符结束,输入不多于1000个字符。

Output
输出字符串中的全部数字

Sample Input
his5is3a3245string14including11number12s

Sample Output
533245141112

HINT

Source
NBU OJ

#include<stdio.h>
#include<string.h>
void main()
{
	int n,i,j=0;
	char str[1000],b[1000];
	gets(str);
	n=strlen(str);
	for(i=0;i<n;i++)
		if(str[i]>='0'&&str[i]<='9')
		{b[j]=str[i];
		j++;}
		for(i=0;i<j;i++)
			printf("%c",b[i]);
		printf("\n");
}
1188 数字移位
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 476 | Solved : 278
Description
有n个整数,要求将前面各数字顺序向后移动m个位置,并将最后面的m个数变成最前面m个数。其中,移动2个位置后的效果如下图所示:
 
 

Input
第一行输入两个正整数:n,m。n表示原始数据的个数,m表示需要向后移动的位置数。
第二行输入这n个原始整数。

Output
输出经过调整后的n个数。

Sample Input
7 3
1 2 5 4 7 8 3

Sample Output
7 8 3 1 2 5 4

HINT
输出时,最后一个数据后面直接换行。

Source
NBU OJ
#include<stdio.h>
void main()
{
	int n,m,i;
	int a[100][100],*p[100];
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<m;i++)
		p[i]=a[i+n-m];
	for(i=m;i<n;i++)
		p[i]=a[i-m];
	for(i=0;i<n-1;i++)
		printf("%d ",*p[i]);
	printf("%d\n",*p[n-1]);
}
1189 逆反的01串
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 527 | Solved : 339
Description
CoCo处于青少年的叛逆时期,有时侯,表现出很强烈的逆反心理,你往东,她往西,你往南,她偏往北。这一次,不知道又是谁惹着她了,好端端的一个个01串,到了她的手里,都变成10串了。请你编个程序来模仿她的行为,将01串(长度≤200),全变成10串吧。

Input
输入一个01串。

Output
输出一个10串。即将输入内容中的0变1,1变0。

Sample Input
0110100100100
1000000010000000000

Sample Output
1001011011011
0111111101111111111

HINT

Source
NBU OJ
#include<iostream>
#include<string>
using namespace std;
int main()
{
      string s;
      while(cin>>s)
      {
           for(int i=0;i<s.length();i++)
            if(s[i]=='0')s[i]='1';
            else s[i]='0';
           cout<<s<<endl;
       }
}

1191 二维数组每行最大值 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 936 | Solved : 581 
Description
求出二维数组每行的最大元素。

Input
输入一个3*4的二维数组。

Output
输出每行的最大值。各占一行。

Sample Input
1 3 5 7
2 6 9 2
11 4 6 5

Sample Output
7
9
11
#include<stdio.h>
void main()
{
	int a[3][4];
	int i,j,m;
	for(i=0;i<3;i++)
		for(j=0;j<4;j++)
			scanf("%d",&a[i][j]);
		for(i=0;i<3;i++)
		{
			m=a[i][0];
			for(j=0;j<4;j++)
				if(m<a[i][j])
					m=a[i][j];
				printf("%d\n",m);
		}
}
1192 约瑟夫问题(1) 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 229 | Solved : 107 
Description
模拟这个游戏。有n个人围成一圈,从第一个人开始沿顺时针方向报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那个人?

Input
输入一个整数n。

Output
输出最后剩下的数。

Sample Input
5

Sample Output
4
#include <stdio.h>
const int M = 3;
int main()
{
int i,n, s = 0;
scanf("%d", &n);
for (i=2;i<=n;++i)
s = (s+M)%i;
printf("%d\n", s+1);
return 0;
}
1193 一维数组元素倒置 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 724 | Solved : 304 
Description
有一个长度为n数组,需要将数组中从指定位置m开始的k个元素倒放在原来的数组中。

Input
第一行输入n,m,k (1<=n<=50)。
 第二行输入数组中的n个数。
m代表元素的实际位置而不是在数组中的下标值。

Output
输出倒置后的数组。

Sample Input
13 3 11
1 2 3 4 5 6 7 8 9 10 11 12 13

Sample Output
1 2 13 12 11 10 9 8 7 6 5 4 3

HINT
最后一个数据的后面直接换行。
#include<stdio.h>
void main()
{
	int a[100];
	int i,j,n,m,k,t;
	scanf("%d%d%d",&n,&m,&k);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	j=m+k-2;
	for(i=m-1;i<j;i++,j--)
	{
		t=a[i];
		a[i]=a[j];
		a[j]=t;
	}
	for(i=0;i<n-1;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
}
1194 一维数组中剔除0 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1391 | Solved : 441 
Description
给定一组数组,将其中的数字0去掉并且输出剩余的元素。

Input
第一行输入一个整数n代表数组长度(1<=n<=50)。
第二行输入这n个数。

Output
输出除0后的数组。

Sample Input
5
1 5 0 6 0

Sample Output
1 5 6
#include<stdio.h>
void main()
{
	int a[50],b[50];
	int i,n,m=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	{
		if(a[i]!=0)
		{b[m]=a[i];
		m++;}
	}
	for(i=0;i<m-1;i++)
		printf("%d ",b[i]);
	printf("%d\n",b[m-1]);
}
T1195
题目描述
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?

输入要求
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。


输出要求
对于每个测试实例,请输出不同走法的数量。


输入样例
2 
2
3

输出样例
1
2

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int a[41];
    a[1]=0;
    a[2]=1;
    a[3]=2;
 
    int i;
    for(i=4;i<=40;i++)
    {
        a[i]=a[i-1]+a[i-2];
    }
 
    int n,k;
    scanf("%d",&n);
 
    while(n--)
    {
        scanf("%d",&k);
        printf("%d\n",a[k]);
    }
return 0;
}
T1196
在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:





输入要求
输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n .(1<=n<=50)

输出要求
对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。

输入样例
1
3
2

输出样例
1
3
2

#include<stdio.h>
 
int main()
{
	__int64 arr[51];
	int num;
	arr[1]=1;arr[2]=2;
	for(int i=3;i<=50;i++)
		arr[i]=arr[i-1]+arr[i-2];
	while(scanf("%d",&num)!=EOF)
	{
		printf("%I64d\n",arr[num]);
	}
	return 0;
}

T1197我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目。比如,一条折线可以将平面分成两部分,两条折线最多可以将平面分成7部分,具体如下所示。 

输入要求
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n,代表折线的数目.

输出要求
对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。

输入样例
2
1
2

输出样例
2
7

#include<stdio.h>
int main(){
	int t;
	scanf("%d",&t);
	int n;
	while(t--){
		scanf("%d",&n);
		printf("%d\n",2*n*n-n+1);
	} 
	return 0;
}


1198 今天星期几 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1234 | Solved : 556 
Description
输入一个正整数表示一个星期中的某一天,若此数字在[1,7]内,则输出对应英文星期名,否则表示输入错误,例如,输入2,程序输出“Tuesday”,输入“16”,程序输出“Illegal day”。

Input
输入一个正整数a表示星期几

Output
这一天对应的英文星期名

Sample Input
2

Sample Output
Tuesday
#include<stdio.h>
void main()
{
int a;
scanf("%d",&a);
switch(a)
{
case 1:printf("Monday\n");break;
case 2:printf("Tuesday\n");break;
case 3:printf("Wednesday\n");break;
case 4:printf("Thursday\n");break;
case 5:printf("Friday\n");break;
case 6:printf("Saturday\n");break;
case 7:printf("Sunday\n");break;
default:printf("Illegal day\n");break;
}
}
T1199
题目描述
输入一个字符串,其中只能包括数字或字母。对应输入的字符串,输出它的类型。如果是仅由数字构成的那么输出digit,如果是仅由字母构成的那么输出character,如果是由数字和字母一起构成的输出mixed。

输入要求
输入一个字符串,长度不超过1000,且字符串中只包括数字或大、小写字母。

输出要求
输出对应的类型。

输入样例
Sun2009

输出样例
mixed

#include<stdio.h>
int main(){
	int t;
	char d[1000];
	int n,i,flag=0,flag2=0;
	gets(d);
	for(i=0;d[i]!='\0';i++)
	{
		if((d[i]>='a'&&d[i]<='z')||(d[i]>='A'&&d[i]<='Z'))
		flag++;
		else if((d[i]>='0'&&d[i]<='9'))
		flag2++;
	}
	if(flag>0&&flag2>0)
		printf("mixed\n");
		else if(flag==0&&flag2>0)
		printf("digit\n");
		else if(flag>0&&flag2==0)
		printf("character\n");
	return 0;
}

1200 求平均值 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 2259 | Solved : 869 
Description
输入10个实数,计算并输出所有大于0的元素的平均值(精确到小数点后2位)。

Input
输入10个实数。

Output
计算大于0的元素的平均值。

Sample Input
-5 2 -6 9 -4 -2 0 6 1 10

Sample Output
5.60
#include<stdio.h>
void main()
{
	double n,i=1,m=0;
	double s=0;
	for(i=1;i<=10;i++)
	{scanf("%lf",&n);
	if(n>0)
	{m++;
	s=s+n;}
	}
	printf("%.2f\n",s/m);
}
1205 梯形面积 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 990 | Solved : 661 
Description
已知梯形上底和下底分别为x和y,高为h,求梯形面积。

Input
输入x、y和h。(双精度类型)

Output
输出梯形面积(保留2位小数)

Sample Input
10 20 5

Sample Output
75.00
#include<stdio.h>
void main()
{
	double a,b,c,s;
	scanf("%lf%lf%lf",&a,&b,&c);
	s=(a+b)*c/2;
	printf("%.2f\n",s);
}
1206 水费问题 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 816 | Solved : 622 
Description
为了加强居民的节水意识,某地区制定了以下生活用水收费标准:每户每月用水未超过7吨时,每吨收费1.0元,并加收0.2元每吨的城市污水处理费;用水若超过7吨(含7吨),则每吨收费1.5元,并加收0.4元每吨的城市污水处理费。输入用水量并计算应交水费。(注:非分段计费)

Input
用水量。(采用浮点类型)

Output
应交水费。(保留2位小数)

Sample Input
7

Sample Output
13.30
#include<stdio.h>
void main()
{
	double m,n;
	scanf("%lf",&n);
	if(n<7)
		m=n*1.2;
	else if(n>=7)
		m=n*1.9;
	printf("%.2f\n",m);
}
1207 读了几页书 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 462 | Solved : 380 
Description
小玲读课外书,第一天读了x页,以后每天要比前一天多读m页,小玲共读了n天,问小玲共读了多少页?

Input
输入x、m和n。

Output
输出小玲n天共读了多少页

Sample Input
12 6 7

Sample Output
210
#include<stdio.h>
void main()
{
	int x,m,n,i,y=0;
	scanf("%d%d%d",&x,&m,&n);
	for(i=1;i<=n;i++)
	{y=y+x;
	x=x+m;}
	printf("%d\n",y);
}
1208 简单算术运算 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1134 | Solved : 430 
Description
输入一个数学表达式,输出运算结果。如输入为3^3,则输出结果27.00;如输入为7*8,则输出结果为56.00。(运算符号局限于+、-、*、/、^ 五种,其余输出“Error”)

Input
输入形式为a+( -、*、/、^ )b,即一个数字、一个运算符号、再一个数字。如3+8。采用双精度类型

Output
输出运算结果,如11.00。保留2位小数

Sample Input
3+8

Sample Output
11.00
#include<stdio.h>
#include<math.h>
void main()
{
	double a,b,c;
	char ch;
	scanf("%lf%c%lf",&a,&ch,&b);
	switch(ch)
	{
	case '*':c=a*b;
printf("%.2f\n",c);break;
	case '+':c=a+b;
printf("%.2f\n",c);break;
	case '-':c=a-b;
printf("%.2f\n",c);break;
	case '/':c=a/b;
printf("%.2f\n",c);break;
	case '^':c=pow(a,b);
printf("%.2f\n",c);break;
	default:printf("Error\n");
	}
}
1209 幂之和 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 896 | Solved : 486 
Description
给定一个n 位整数 (n≥3 ),判断它的每个位上的数字的 n 次幂之和是否等于它本身。
例如:3位数153(此时n=3),1^3 + 5^3 + 3^3=153
         4位数8208(此时n=4),8^4+2^4+0^4+8^4=8208

Input
键盘输入一个整数x

Output
若x符合条件则输出“Yes”,否则输出“No”。输出不包含双引号。

Sample Input
92727

Sample Output
Yes
#include<stdio.h>
#include<math.h>
void main()
{
	int i,x,m=0,n=0;
	scanf("%d",&x);
	for(i=x;i>0;i=i/10)
		n++;
for(i=x;i>0;i=i/10)
	m=m+pow(i%10,n);
	if(m==x)
		printf("Yes\n");
	else
		printf("No\n");
}
1211 还是鸡兔同笼 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1315 | Solved : 612 
Description
一个笼子里面关了鸡和兔子(鸡有2只脚,兔子有4只脚,没有例外)。已经知道了笼子里面脚的总数a,问笼子里面至少有多少只动物,至多有多少只动物。

Input
第一行是测试数据的组数n,后面跟着n行输入。每组测试数据占一行,每行包含一个正整数a,代表笼子里面脚的总数。

Output
输出包含n行,每行对应一个输入,包含2个正整数,第一个是最少的动物数,第二个是最多的动物数。如果没有满足要求的答案,则输出两个0。

Sample Input
2
3
20

Sample Output
0 0
5 10
#include<stdio.h>
void main()
{
	int i,N,n;
	scanf("%d",&N);
	for(i=1;i<=N;i++)
	{scanf("%d",&n);
	if(n%2!=0)
	printf("0 0\n");
	else if(n%2==0&&n%4==0)
	printf("%d %d\n",n/4,n/2);
	else 
	printf("%d %d\n",n/4+1,n/2);
	}
}
1212 小于某数的整数和 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 323 | Solved : 263 
Description
给定一个正整数a,以及另外的5个正整数,请问:这5个正整数中,小于a的整数的和是多少?

Input
先输入一个正整数a,再输入另外5个正整数。

Output
计算这5个整数中,小于a的整数的和是多少,输出结果。

Sample Input
10 7 8 9 11 2

Sample Output
26
#include<stdio.h>
void main()
{
	int x,i,y=0;
	int a[5];
	scanf("%d",&x);
	for(i=0;i<5;i++)
		scanf("%d",&a[i]);
	for(i=0;i<5;i++)
		if(x>a[i])
			y=y+a[i];
		printf("%d\n",y);
}
1217 超市硬币处理机 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1026 | Solved : 335 
Description
超市前放置了一个硬币处理机,可以帮你把零钱转换为存款单。在实际应用中,机器中将有相应装置自动识别并计算你的零钱的数目,但是我们现在只能先进行一个手工的小实验,由你自己输入每种硬币的数目,然后编写程序将其转换成存款单。

Input
依次输入1元、5角、1角的零钱的个数。假如输入三个整数3 10 25,则表示有3个1元硬币、10个5角硬币和25个1角的硬币。

Output
输出存单金额,如对上例的输入,输出为
Dollars=10
Change=50
表示存单上的整数金额为10元,零钱金额为50分。
即要求Dollars后显示的是**元的信息,Change后面显示的是**分的信息。

Sample Input
3 0 10

Sample Output
Dollars=4
Change=0
#include<stdio.h>
void main()
{int Dollars,Change,a,b,c,d;
  scanf("%d%d%d",&a,&b,&c);
  d=a*10+b*5+c;
  printf("Dollars=%d\n",d/10);
  printf("Change=%d\n",(d%10)*10);
}
1218 正方形还是圆形 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1240 | Solved : 700 
Description
编写包含分支结构的交互程序,首先从键盘读入一个浮点数a,然后再读入一个小写字母(s或c),如果读入的字母是s,则计算并输出正方形面积;如果读入的字母是c,则计算并输出圆面积。

Input
输入一个浮点数和一个小写字母(s或c),假设不会出现其他字母。数字和字母紧挨着输入,中间不要加空格。

Output
根据输入的字母为s或c,决定输出正方形面积或是圆面积,保留2位小数。

Sample Input
2s

Sample Output
4.00

HINT
圆周率取3.14。
#include<stdio.h>
void main()
{
	double s1,n;
	char m;
	scanf("%lf%c",&n,&m);
	if(m=='c')
		s1=3.14*n*n;
	else if(m=='s')
		s1=n*n;
	printf("%.2f\n",s1);
}
1220 火车托运费 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 587 | Solved : 411 
Description
设乘坐火车托运行李时按下列式子收费
应交费用 y= 0                (0<=x<=20)
                 y= (x-20)*2     (20<x<=40)<x<=40)< span=""></x<=40)<>
                  y=(x-40)*5+40  (x>40)
编写程序计算应交金额(元)。

Input
输入行李的重量x(整数)。

Output
输出应交的金额。

Sample Input
40

Sample Output
40
#include<stdio.h>
void main()
{
	int x,y;
	scanf("%d",&x);
	if(x>=0&&x<=20)
		y=0;
	else if(x>20&&x<=40)
		y=(x-20)*2;
	else if(x>40)
		y=(x-40)*5+40;
	printf("%d\n",y);
}
1222 表示成两个数的平方和 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1623 | Solved : 723 
Description
输入一个正整数N,找出所有满足X^2+Y^2=N的正整数对X和Y。

Input
输入一个正整数N。

Output
输出这两个正整数X和Y,满足X^2+Y^2=N,输出时要求X<=Y。如果无解则不需要输出任何信息。

Sample Input
50

Sample Output
1 7
5 5

HINT
当有多组输出时,按照X从小到大的顺序排列。
#include<stdio.h>
#include<math.h>
void main()
{
     int i,j,n;
      scanf("%d",&n);
      for(i=pow(n,0.5);i>=1;i--)
	  {for(j=1;j<=i;j++)
	  if(j*j+i*i==n)
		  printf("%d %d\n",j,i);}
}
1231 统计闰年(1) 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 788 | Solved : 403 
Description
计算出从2000年开始X年(含2000和2000+X)之间的闰年并输出。

Input
输入整数x。

Output
输出属于闰年的年份,每个年份一行,输出后换行。

Sample Input
50

Sample Output
2000
2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
2048
#include<stdio.h>
int main()
{
	int X,i,a;
	scanf("%d",&X);
	for(i=0;i<=X;i++)
	{	a=2000+i;
      if(a%4==0&&a%100!=0||a%400==0)
		  printf("%d\n",a);}
		return 0;
}
1232 石头剪刀布 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1463 | Solved : 668 
Description
CoCo要和Tom玩石头剪刀布的游戏,规则是石头砸剪刀、剪刀剪布、布包石头。用手玩的话谁都会,没什么稀奇的,今天他们换个玩法,用数字代替手势来完成石头剪刀布的游戏。假设0表示石头,1表示剪刀,2表示布,每人在纸上写一个数字(数字范围局限于0、1、2),然后同时展示所写的数字,如果CoCo的数字胜出了则输出Win,否则一律输出Lose。

Input
输入两个数字(数字范围局限于0、1、2)。

Output
如果第一个数字胜出了则输出Win,否则一律输出Lose。输出后换行。

Sample Input
0 2

Sample Output
Lose
#include<stdio.h>
void main()
{int a,b;
 scanf("%d%d",&a,&b);
   if(a==0)
   {if(b==1) printf("Win\n");
   else printf("Lose\n");}
   if(a==1)
    {if(b==2) printf("Win\n");
   else printf("Lose\n");}
   if(a==2)
   {if(b==0) printf("Win\n");
   else printf("Lose\n");}
}
1233 勤劳的蚂蚁 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1256 | Solved : 624 
Description
有两只勤劳的蚂蚁在准备食物,为了自我激励一下,它们打算开展比赛,看谁在一段时间内准备的食物多一些。你能帮忙做个裁判吗,来统计一下哪只蚂蚁准备得更加多一些?

Input
输入有若干行,每行2个数字,第一个整数表示蚂蚁(1表示1号蚂蚁,2表示2号蚂蚁,不会出现其他数字)。第二个整数表示该蚂蚁带回的食物数量,假设该数据都在合法范围内。
当输入两个数字都为0(即0 0)时表示输入结束。

Output
输出拖回食物多的蚂蚁的编号和食物总数量。如果相同,输出“equal”(输出不包含双引号)。输出后换行。

Sample Input
1 2
2 9
1 7
2 6
1 1
2 0
1 2
2 11
0 0

Sample Output
2 26
#include<stdio.h>
int main()
{
	int x,y,z=0,a=0;
	scanf("%d%d",&x,&y);
		while(x!=0||y!=0)
		{
			if(x==1)
			z=y+z;
			else
				a=y+a;
			scanf("%d%d",&x,&y);

		}
		if(a>z)
			printf("%d %d\n",2,a);
		else if(a<z)
			printf("%d %d\n",1,z);
		else
			printf("equal\n");
		return 0;
}
1235 回流的时光 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 811 | Solved : 491 
Description
紧追时尚的你,一定看过电影“波斯王子—时之刃”吧,是否对时光倒流的能力念念不忘?时之刃里的沙子流过沙漏时,时光就会倒流。现在假设时之刃里的沙子有不同的颜色,一粒红色沙子可以让时光回流4S(4秒),一粒黄色沙子可以回流3S,一粒白色沙子可以回流1S,其他颜色无效。请根据题目条件计算王子这次能回流的时光有几秒。

Input
输入共三行,每一行包含沙子的颜色(0、1、2分别表示红色、黄色、白色)和粒数。

Output
输出回流时光的总秒数,输出后换行。

Sample Input
0 100
1 10
2 1

Sample Output
431
#include<stdio.h>
void main()
{int x,y,w=0,i=1;
while(i<4)
{scanf("%d%d",&x,&y);
  if(x==0) w=w+y*4;
  if(x==1) w=w+y*3;
  if(x==2) w=w+y;
  i++;
}
printf("%d\n",w);
}
1240 约瑟夫问题(2) 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 300 | Solved : 175 
Description
模拟这个游戏。n个人围坐一圈,从第1个人开始数,沿顺时针方向数到m,最后数到的人被淘汰。然后接下去数,数到m,再淘汰一人。重复上述过程,直到剩下1人为止。剩下的这个人是获胜者。

Input
输入两个整数n和m。n<1000。

Output
依次输出每次被淘汰的人的编号以及最后获胜者的编号。每个数字占据一行。

Sample Input
5  3

Sample Output
3
1
5
2
Win=4
#include<stdio.h>
#define MAX 1000
int main()
{
int n;
int num[MAX];
int move=0;
int m;
int i=0;
int j=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
num[i]=1;
i=0;
while(move<n-1)
{
i%=n;
while(i<n)
{
j%=m;
if(num[i]==1)
j++;
if(j==m)
{
num[i]=0;
printf("%d\n",i+1);
move++;
}
i++;
}
}
for(i=0;i<n;i++)
if(num[i])
{
printf("Win=%d\n",i+1);
break;
}
return 0;
}
1254 数值交换 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 1009 | Solved : 302 
Description
编写程序,输入一个正整数n(n在[1,10]之间),接着输入n个整数,然后将最小值与第一个数交换,最大值与最后一个数交换,再输出交换后的n个数。

Input
输入一个正整数n(n在[1,10]之间),接着输入n个整数。(假设这n个整数互不相同)

Output
输出交换后的n个数。每个数据后面都跟一个空格,一行输出完毕后换行。

Sample Input
样例1输入
6 19 87 3 -98 77 6

样例2输入
6 6 5 4 3 2 1

Sample Output
样例1输出
-98 6 3 19 77 87

样例2输出
1 5 4 3 2 6
#include<stdio.h>
#define n 10
void main()
{
	int s[n],i,x,t,y,c,d;
	scanf("%d",&x);
    for(i=0;i<x;i++)
		scanf("%d",&s[i]);
	c=s[0];
	for(i=0;i<x;i++)
	{
		if(s[i]<c)
		{
			c=s[i];
            y=i;
		}
	}
	t=s[0];
	s[0]=c;
   s[y]=t;
    d=s[0];
   	for(i=0;i<x;i++)
	{
		if(s[i]>d)
		{
			d=s[i];
            y=i;
		}
	}
	t=s[x-1];
	s[x-1]=d;
   s[y]=t;
	for(i=0;i<x;i++)
		printf("%d ",s[i]);
	printf("\n");

}
1262 无重复的排序 
Time Limit : 1000 MS | Memory Limit : 32768 KB 
Submits : 569 | Solved : 327 
Description
输入一组整型数据,每个数据都大于0且小于100,输入遇0时结束。要求将输入的数排序,并去掉相同的数,将排序结果从小到大输出。

Input
输入只有一组数据,输入数据不超过20个。 所有输入都在正确的范围内。

Output
输出数据一个一行。

Sample Input
16 89 9 8 6 16 9 0

Sample Output
6
8
9
16
89
#include<stdio.h>
void main()
{
	int a[20];
	int i,j,k,temp,minloc,n;
	for(i=0,k=0;;i++)
	{scanf("%d",&a[i]);
	if(a[i]==0)
		break;
	else
		k++;
	}
	for(i=0;i<k-1;i++)
	{
		minloc=i;
		for(j=i+1;j<k;j++)
			if(a[j]<a[minloc])
				minloc=j;
			if(minloc!=i)
			{temp=a[i];a[i]=a[minloc];a[minloc]=temp;}
	}
		for (i=0;i<k;i++)
for (j=0;j<k-i;j++)
{
if (a[j]!=a[j+1])
{ 
continue;
}
else
{
for (n=j+1;n<k;n++)
{
a[n]=a[n+1];
}
k--;
}
}
for(i=0;i<k;i++)
printf("%d\n",a[i]);
}
1318 唯一的最好
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 983 | Solved : 377
Description
我们经常听到:“唯一的总是最好的。”不知道是哪个名人说的(好像是我说的。。。暴扁中。。。)。假设现在有一堆宝物,有些品种的宝物数量有多个,物以稀为贵,多了就不稀奇了。你能找到数量只有一个的宝物吗?宝物用小写英文字母a-z表示,只有26种哦,亲。

Input
输入为一行字符串,全部由小写字母表示,长度不大于100。如“abcdea”表示宝物b、c、d、e各出现了1次,而宝物a出现了2次。

Output
输出只出现一次的那种宝物的对应字符,如果出现一次的字符有多个,那么输出首先出现的那个字符即可。如果没有只出现一次的字符,那么输出“NO only character”。

Sample Input
abcdefggfdca

Sample Output
b

HINT

Source
NBU OJ
#include<stdio.h>
#include<string.h>
#define m 1000
void main()
{
	char str[m];
	int i=0,c,t,b=0,j;
	gets(str);
	t=strlen(str);
	while(str[i]!='\0')
	{
		c=0;
		for(j=0;j<t;j++)
		{
			if(str[i]==str[j])
				continue;
			else
				c++;
		}
		if(t-1==c)
		{
			printf("%c\n",str[i]);
			break;
		}
		else
			b++;
		i++;
	}
	if(b==t)
		printf("NO only character\n");
	
	
}
1370 庆功晚宴
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 433 | Solved : 263
Description
天下历圈圈年,A国与C国发生了战争。C国完胜后开始了狂欢。突然某人大喝一声“我消灭了最多的敌人!”。众人均不服,都把自己在每场战役中消灭的敌人数目晒了出来,可是大家七嘴八舌的,最后也没搞清楚到底谁杀敌的总数最多。现在就需要你来帮忙统计战功,找出功劳最大的英雄。

Input
首先输入一个整数n,表示有n个人参与评选。(n<100)
接下来的n行,每行输入一个姓名跟一个整数m。然后输入 m个整数,表示该将领在每场仗战役中消灭敌人的数目。

Output
输出英雄的名字,以及总的杀敌数量。数量相同则按照名字的字典序,输出排在最前面的那个英雄。

Sample Input
5
Alexandra 5 499 232 11 23 67
Bette 3 2222 342 42
Debbie 6 23 67 77 88 99 66
Owen 2 9999 2
Jesse 4 123 456 789 345

Sample Output
Owen 10001

HINT
姓名不包含空格

Source
NBU OJ
#include<stdio.h>
#include<string.h>
#define N 100
struct hero
{
	char str[20];
	int num[20];
	int sum;
};
typedef struct hero H;
void sort(H *p,int n)
{
	H t;
	int i,j;
	for(i=0;i<n-1;i++) 
		for(j=0;j<n-i-1;j++)
		{
			if(p[j].sum<p[j+1].sum)
			{
				t=p[j];
				p[j]=p[j+1];
				p[j+1]=t;
			}
			else if(p[j].sum==p[j+1].sum)
			{
				if(strcmp(p[j].str,p[j+1].str)>0)
			{
				t=p[j];
				p[j]=p[j+1];
				p[j+1]=t;
			}
			}
           
		}
		
}

int main()
{
	H STD[N];
	int i,n,m,j,t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	scanf("%s%d",STD[i].str,&m);
	for(j=0;j<m;j++)
         scanf("%d",&STD[i].num[j]);
	for(t=0;t<n;t++)
	{
		STD[i].sum=0;
		for(j=0;j<m;j++)
			STD[i].sum=STD[i].sum+STD[i].num[j];
	}
	}
	sort(STD,n);

	printf("%s %d\n",STD[0].str,STD[0].sum);
	return 0;
}
1371 情人节的百宝箱
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 340 | Solved : 181
Description
时值情人节,青羽送了一个百宝箱给小衣,大小为n×m,每个格子里都有一件物品,物品价值为vi。现在需要你将这些格子按照价值从大到小排序。价值相同行号小的在前,行号再相同时,则列号在前的优先。

Input
第一行输入两个整数n,m表示百宝箱的大小。
接着输入n行m列的数据,分别表示对应格子里的物品的价值。

Output
按照要求排序后,每行输出一个行号、一个列号以及该行列号表示的格子里的物品价值。

Sample Input
3 5
19 5 12 15 4
16 7 14 5 19
19 10 1 17 2

Sample Output
1 1 19
2 5 19
3 1 19
3 4 17
2 1 16
1 4 15
2 3 14
1 3 12
3 2 10
2 2 7
1 2 5
2 4 5
1 5 4
3 5 2
3 3 1


HINT
输出时,格子的行列数与日常生活的计数习惯一致,即从1开始。

Source
NBU OJ
#include<stdio.h>
struct gift
{
	int pri,x,y;
};
int main()
{
	gift a[59999],temp;
	int q,w,e,r,t=0;
	scanf("%d%d",&q,&w);
	for(e=0;e<q;e++)
		for(r=0;r<w;r++,t++)
		{
			scanf("%d",&a[t].pri);
			a[t].x=r+1;
			a[t].y=e+1;
		}
	for(e=0;e<q*w;e++)
		for(r=e;r<q*w;r++)
		{
			if(a[e].pri<a[r].pri)
			{
				temp=a[e];
				a[e]=a[r];
				a[r]=temp;
			}
			else if(a[e].pri==a[r].pri)
			{
				if(a[e].y>a[r].y)
				{
					temp=a[e];
					a[e]=a[r];
					a[r]=temp;
				}
				else if(a[e].y==a[r].y&&a[e].x>a[r].x)
				{
					temp=a[e];
					a[e]=a[r];
					a[r]=temp;
				}
			}
		}
	for(e=0;e<q*w;e++)
	{
		printf("%d %d %d\n",a[e].y,a[e].x,a[e].pri);
	}
	return 0;

}
1372 考试之后
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 741 | Solved : 391
Description
又是一次期中考。考完之后肯定少不了成绩的排名。可是面对这么多的成绩,老师也觉得累。于是向熟悉编程的你求助。计入排名的考试只有语文数学跟英语三门。按照平均分从高到低输出。

Input
先输入一个整数n,表示有n个学生。(0 < n < 300)
 接下来n行,每行有4个数据,分别代表学号,语文成绩,数学成绩,英语成绩。

Output
按照平均分从大到小输出这n个学生的语文成绩、数学成绩、英语成绩。平均分相同时,按照学号的升序来。

Sample Input
4
1023 88 75 65
1033 99 59 70
1187 77 82 83
1054 64 86 92

Sample Output
1054 64 86 92
1187 77 82 83
1023 88 75 65
1033 99 59 70

HINT

Source
NBU OJ
#include<stdio.h>
int main()
{
	int a[300][5];
	int n,i,j,s;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		for(j=0;j<4;j++)
			scanf("%d",&a[i][j]);
	for(i=0;i<n;i++)
		a[i][4]=a[i][1]+a[i][2]+a[i][3];
	for(s=1;s<n;s++)
	for(i=n-1;i>0;i--)
	{
		if(a[i][4]==a[i-1][4]&&a[i][0]<a[i-1][0])
		{
			for(j=0;j<5;j++)
				a[n][j]=a[i-1][j];
			for(j=0;j<5;j++)
				a[i-1][j]=a[i][j];
			for(j=0;j<5;j++)
				a[i][j]=a[n][j];
		}
		if(a[i][4]>a[i-1][4])
		{
			for(j=0;j<5;j++)
				a[n][j]=a[i-1][j];
			for(j=0;j<5;j++)
				a[i-1][j]=a[i][j];
			for(j=0;j<5;j++)
				a[i][j]=a[n][j];
		}
	}
	for(i=0;i<n;i++)
		for(j=0;j<4;j++)
		{
			if(j==3)
			printf("%d\n",a[i][j]);
			else
				printf("%d ",a[i][j]);
		}
	return 0;
}
1373 CoCo的成绩Ⅰ
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 271 | Solved : 150
Description
上小学的CoCo刚考完期末考试,拿到成绩的她想知道自己的成绩如何,你能帮帮她吗?

Input
第一行输入一个整数n表示有n个学生( 1 < N < 100);
第二行输入这n个学生的姓名(少于10个字符)、语文成绩、数学成绩、英语成绩。

Output
分两行输出总分最高和最低的学生名字和各项成绩(如有相同总分则输出第一次出现的学生)。

Sample Input
3
Tom 65 45 87
CoCo 78 89 93
Mark 87 67 54

Sample Output
CoCo 78 89 93
Tom 65 45 87

HINT

Source
NBU OJ
#include<stdio.h>
struct student
{
char name[10];
int score[3];
};
void main()
{
int i,j,n,max,min,maxl=0,minl=0;
int sum[100];
struct student s[100];
scanf("%d",&n);
for(i=0;i<100;i++)
sum[i]=0;
for(i=0;i<n;i++)
{
scanf("%s",s[i].name);
for(j=0;j<3;j++)
{
scanf("%d",&s[i].score[j]);
sum[i]=sum[i]+s[i].score[j];
}
}
max=min=sum[0];
for(i=1;i<n;i++)
{
if(max<sum[i]) {maxl=i;max=sum[i];}
if(min>sum[i]) {minl=i;min=sum[i];}
}
printf("%s ",s[maxl].name);
for(i=0;i<2;i++)
printf("%d ",s[maxl].score[i]);
printf("%d\n",s[maxl].score[i]);
printf("%s ",s[minl].name);
for(i=0;i<2;i++)
printf("%d ",s[minl].score[i]);
printf("%d\n",s[minl].score[i]);
}
1374 小CC的成绩Ⅱ
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 306 | Solved : 161
Description
上小学的小CC刚考完期末考试,拿到成绩的她想知道自己的成绩如何,你能帮帮她吗?

Input
第一行输入N(1< N < 1 00)个学生,第二行输入2--N+1个学生的姓名s(少于10个字符)、语文成绩c、数学成绩m、英语成绩e。

Output
分三行输出语文、数学、英语的平均分(结果保留两位小数)。

Sample Input
3
zhangsan 65 45 87
lisi 78 89 93
lkfhi 87 67 54

Sample Output
76.67
67.00
78.00

HINT

Source
NBU OJ
#include<stdio.h>
#define N 100
struct student 
{
	char name[10];
	int num[3];
	int sum[3];
	double ave;
};
typedef struct student H;
void main()
{
	H stu[N];
	int i,j,n,t=0,x=0,a[3];
	double b[3];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",stu[i].name);
		for(j=0;j<3;j++)
			scanf("%d",&stu[i].num[j]);
	}
	for(j=0;j<3;j++)
	{
	  a[j]=0;
	  for(i=0;i<n;i++)
		  a[j]=a[j]+stu[i].num[j];
	  b[j]=a[j]/(1.0*n);
	}

		
	for(i=0;i<3;i++)
		printf("%.2f\n",b[i]);
}
1418 折叠方阵
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 108 | Solved : 90
Description
n阶折叠方阵是指,从指定起始数开始的n^2个连续整数折叠为n行n列的数方阵,起始数置于方阵的左上角,然后从起始数开始递增,按顺时针方向层层折叠地排列为顺时针折叠方阵,按逆时针方向层层折叠地排列为逆时针折叠方阵。

Input
输入起始数a与阶数n以及整数1(表示输出顺时针折叠方阵)或2(表示输出逆时针折叠方阵)。

Output
输出对应的折叠方阵。每个数据用%4d控制输出格式。

Sample Input
10 4 1

Sample Output
  10  11  14  19
  13  12  15  20
  18  17  16  21
  25  24  23  22

HINT

Source
NBU OJ
#include<stdio.h>
void main()  
 {
	 int a,i,n,p,m,x,y,z[50][50];    
	 scanf("%d%d",&a,&n);    
	 scanf("%d",&p);  
	 z[1][1]=a;      
	 for (i=2;i<=n;i++)       
	 { x=1;y=i;       
	 z[x][y]=a+(i-1)*(i-1);      
	 while(x<i)        
		 z[++x][y]=z[x][y]+1;   
     while (y>1)          
		 z[x][--y]=z[x][y]+1;   
	 }        
	 for (x=1;x<=n;x++)         
	 { for (y=1;y<=n;y++)         
     if (p==1)              
		 printf("%4d",z[x][y]); 
	 else              
		 printf("%4d",z[y][x]);
	 printf("\n");
	 }
 }
1420 “山寨”菲波那契数列
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 666 | Solved : 388
Description
这年头,什么东西都玩山寨,我们也来凑个热闹吧。菲波那契数列你当然是熟悉的,那么看一个“山寨”菲波那契数列吧,它的递推式如下: 式中a和b是常数。给定a、b和n,计算对应的F(n) 的值。
 

Input
第一行输入测试用例的个数T;后面T行分别输入测试的用例,每个测试一行,内容分别为整数a、b和n。已知数据范围:a<=10,b<=10,n<=30。

Output
输出对应的F(n)的值,每个样例结果占据一行。

Sample Input
2
1 2 3
1 3 6


Sample Output
3
24

HINT

Source
The 9th NBU Programming Contest
#include<stdio.h>
int main()
{
	int f[31];
	int a,b,n,i,t,j;
	scanf("%d",&t);
	for(j=1;j<=t;j++)
	{
		scanf("%d%d%d",&a,&b,&n);
		f[1]=a;
		f[2]=b;
		for(i=3;i<=n;i++)
		{
			if(i%2!=0)
				f[i]=f[i-1]+f[i-2];
			else if(i%2==0)
				f[i]=f[i-1]+f[i-2]+f[i-3];
		}
		printf("%d\n",f[n]);
	}
	return 0;
}
1429 OJ上的简单排名
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 738 | Solved : 385
Description
你是第一次参加这样的程序设计比赛吗?那你知道OJ上是怎样进行排名的吗?我把部分规则告诉你,你试着来做个简单的排名吧。

Input
每个输入文件只包含一组数据。 第一行输入一个整数N,表示有N个队参加了比赛;后面N行分别输入测试的用例,每个测试用例一行,内容分别为整数Ti、Si和Pi,Ti代表队伍的编号ID,每个队伍的编号都是1~N且各不相同,Si代表队伍解出的题数,Pi代表罚时。假设所有队伍解出的题数都是不相同的。 (0 < N ≤100,0 ≤ Si ≤100,0 ≤ Pi ≤10000 )

Output
按解出题数从高到低的顺序输出队伍的编号ID,两两间以空格分隔,最后一个ID之后没有空格。

Sample Input
3
3 2 200
2 1 100
1 3 300

Sample Output
1 3 2


HINT
虽然最后一个ID后面没空格,但回车还是照常得加的。

Source
The 9th NBU Programming Contest
#include<stdio.h>
#include<string.h>
#define N 100
struct hero
{
	int Ti;
	int Si;
	int Pi;
};
typedef struct hero H;
void sort(H *p,int n)
{
	H t;
	int i,j;
	for(i=0;i<n-1;i++) 
		for(j=0;j<n-i-1;j++)
		{
			if(p[j].Si<p[j+1].Si)
			{
				t=p[j];
				p[j]=p[j+1];
				p[j+1]=t;
			}          
		}
		
}

int main()
{
	H STD[N];
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d%d%d",&STD[i].Ti,&STD[i].Si,&STD[i].Pi);
	sort(STD,n);
    for(i=0;i<n;i++)
	{
		if(i!=n-1)
	printf("%d ",STD[i].Ti);
		else
        printf("%d\n",STD[i].Ti);
	}
	return 0;
}
1432 三角图形输出
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 832 | Solved : 389
Description
输出下面的图形
    *
  ***
*****
(网页显示可能会不正常,请注意,此处是一个正三角形,最后一行是顶格输出的)

Input
无

Output
输出*组成的正三角图形。

Sample Input

Sample Output
  *

 ***

*****

HINT

Source
NBU OJ
#include<stdio.h>
void main()
{
	
	printf("  *\n");
	printf(" ***\n");
	printf("*****\n");
}
1434 鸡、兔、鸟同笼
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 794 | Solved : 551
Description
鸡兔同笼的问题你已经非常熟悉了,那么我们今天增加点难度吧。九头鸟(传说中的一种怪鸟,它有九个头,二只脚)、鸡和兔子关在一个笼子里,数数它们的头数正好是k,数数它们的脚数也正好是k。请计算其中九头鸟、鸡和兔子各有多少只?(九头鸟、鸡和兔子确保至少各有1只)

Input
输入数据只包含一个整数k(k<=100),且保证有解。

Output
依次输出九头鸟、鸡和兔子的数目,以单个空格作间隔。 如果有多种情况,则每种情况占据一行。九头鸟少的情况排前面。(“那九头鸟个数一样的情况哪个排前面呢?”“随你咯,看运气吧。”)

Sample Input
100

Sample Output
7 31 6
8 14 14

HINT

Source
The 9th NBU Programming Contest
#include<stdio.h>
void main()
{
	int k,n,j,t;
	scanf("%d",&k);
	for(n=1;n<(k/9);n++)
	{
		j=(3*k-34*n)/2;
		t=(16*n-k)/2;
		if(j>=1&&j<=k&&t>=1&&t<=k)
			printf("%d %d %d\n",n,j,t);
	}
}
1437 结构体的嵌套
Time Limit : 1000 MS | Memory Limit : 32768 KB
Submits : 1026 | Solved : 586
Description
做个简单的结构体嵌套吧。设计一个结构体,包含学生姓名、性别、出生日期。其中出生日期又包含年、月、日三部分信息。

Input
输入学生姓名、性别、出生日期。

Output
输出学生姓名、性别、出生日期。

Sample Input
Susan Wang
f
1992 7 26

Sample Output
Susan Wang
f
1992 7 26

HINT
将出生日期也设计成一个结构体。姓名长度不超过20个字符。

Source
NBU OJ

#include <stdio.h>
struct point
	{
	int year;
		int month;
		int day;
	};
struct stu
{		
	char name[1000];
	char sex;
	struct point y;

};
void main()
{	
	struct stu a;	
	gets(a.name);
	scanf("%c",&a.sex);
	scanf("%d%d%d",&a.y.year,&a.y.month,&a.y.day);
	puts(a.name);
	printf("%c\n",a.sex);
	printf("%d %d %d\n",a.y.year,a.y.month,a.y.day);

}
1446 对称方阵Ⅰ
Time Limit : 1000 MS | Memory Limit : 65536 KB
Submits : 316 | Solved : 195
Description
观察以下所示的方阵的构造特点,总结归纳其构造规律,设计并输出如图中所示形式的n(奇数)阶对称方阵。
1 2 3 4 3 2 1 
2 2 3 4 3 2 2
3 3 3 4 3 3 3
4 4 4 4 4 4 4
3 3 3 4 3 3 3
2 2 3 4 3 2 2
1 2 3 4 3 2 1

Input
输入一个正整数n(n≤25),且n为奇数。

Output
输出n阶的对称方阵。

Sample Input
5

Sample Output
  1  2  3  2  1 
  2  2  3  2  2
  3  3  3  3  3
  2  2  3  2  2
  1  2  3  2  1 

HINT
输出数据用%3d控制

Source
NBU OJ
#include<stdio.h>
#include<math.h>
#define N 200
void main()
{
	int x,m,i,j,k=0;
	int a[N][N];
	scanf("%d",&x);
	m=(x+1)/2;
	for(i=1;i<=x;i++)
		for(j=0;j<=x;j++)
		{
			if(i+j<=x+1&&i<=j||i+j>=x+1&&i>=j)
				a[i][j]=m-fabs(m-j);
			if(i+j<x+1&&i>j||i+j>x+1&&i<j)
               a[i][j]=m-fabs(m-i);
		}
		for(i=1;i<=x;i++)
		{
			for(j=1;j<=x;j++)
			  printf("%3d",a[i][j]);
			printf("\n");
		}
			  
}
1510 26进制问题
Time Limit : 1000 MS | Memory Limit : 65536 KB
Submits : 306 | Solved : 114
Description
给定一个十进制正整数,将其转化成26进制数输出,其中用A表示0, B表示1, ... , Z表示25。

Input
输入十进制正整数N( 0 <= N <= 1,000,000,000 ),并以-1为结束符。

Output
输出转换得到的26进制数。

Sample Input
26
676
-1

Sample Output
BA
BAA

HINT
有多组测试数据

Source
NBU OJ
#include<iostream>
using namespace std;
int main()
{ 
 int N,i,j;
  char a[100000];
  while(cin>>N&&N!=-1)
  {
	  for(i=1;;i++)
	  {

		  a[i]=N%26+65;
		  N=N/26;
		  if(N==0)
			  break;
	  }
	  for(j=i;j>=1;j--)
		  printf("%c",a[j]);
	  printf("\n");
	  
  }
  return 0;
}
1815 猜数字
Time Limit : 1000 MS | Memory Limit : 65536 KB
Submits : 71 | Solved : 47
Description
猜数字游戏是gameboy最喜欢的游戏之一。游戏的规则是这样的:计算机随机产生一个四位数,然后玩家猜这个四位数是什么。每猜一个数,计算机都会告诉玩家猜对几个数字,其中有几个数字在正确的位置上。 比如计算机随机产生的数字为1122。如果玩家猜1234,因为1,2这两个数字同时存在于这两个数中,而且1在这两个数中的位置是相同的,所以计算机会告诉玩家猜对了2个数字,其中一个在正确的位置。如果玩家猜1111,那么计算机会告诉他猜对2个数字,有2个在正确的位置。 现在给你一段gameboy与计算机的对话过程,你的任务是根据这段对话确定这个四位数是什么。

Input
输入数据有多组。每组的第一行为一个正整数N(1<=N<=100),表示在这段对话中共有N次问答。在接下来的N行中,每行三个整数A,B,C。gameboy猜这个四位数为A,然后计算机回答猜对了B个数字,其中C个在正确的位置上。当N=0时,输入数据结束。

Output
每组输入数据对应一行输出。如果根据这段对话能确定这个四位数,则输出这个四位数,若不能,则输出"Not sure",输出不包含双引号。

Sample Input
6 
4815 2 1 
5716 1 0 
7842 1 0 
4901 0 0 
8585 3 3 
8555 3 2 
2 
4815 0 0 
2999 3 3 
0 

Sample Output
3585 
Not sure 


HINT

Source
NBU OJ
#include<stdio.h>
bool check1(int num1,int num2,int t)
{
    int a[4],b[4];
    int c[4];
    int i,j;
    for(i=0;i<4;i++)
    {
        a[i]=num1%10;
        num1/=10;
        b[i]=num2%10;
        num2/=10;
        c[i]=0;
    }   
    int m=0;
    for(i=0;i<4;i++)
       for(j=0;j<4;j++)
          if(c[j]==0&&a[i]==b[j])
          {
              m++;
              c[j]=1;
              break;
          }    
    if(m==t)  return true;
    else return false;
}  
bool check2(int num1,int num2,int t)
{
    int a[4],b[4];
    int i,j;
    int m=0;
    for(i=0;i<4;i++)
    {
        a[i]=num1%10;
        num1/=10;
        b[i]=num2%10;
        num2/=10;
        if(a[i]==b[i]) m++;
    }   
    if(m==t)  return true;
    else  return false; 
}  
int main()
{
    int a[101],b[101],c[101];
    int cnt,res;
    int n,i,j;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<n;i++)
           scanf("%d%d%d",&a[i],&b[i],&c[i]);
        cnt=0;
        for(i=1000;i<=9999;i++)
        {
            for(j=0;j<n;j++)
            {
                  if(check1(i,a[j],b[j])==false)break;
                  if(check2(i,a[j],c[j])==false)break;
            }  
            if(j>=n)
            {
                cnt++;
                res=i;
            } 
            if(cnt>=2)break;     
        }
        if(cnt==0||cnt>=2) printf("Not sure\n");
        else printf("%d\n",res);    
    }   
    return 0; 
}
2469 熊抱
Time Limit : 1000 MS | Memory Limit : 65536 KB
Submits : 295 | Solved : 155
Description
小朋友们在游乐场里玩耍,游乐场里有很多大大小的彩色圆形柱子,小朋友喜欢每个柱子都去熊抱一下。柱子呢有粗有细的,如果太粗了小朋友就无法完全将其抱住。现在告诉你10根柱子的半径,以及小朋友的臂展,那么有几根柱子小朋友可以完全抱的住呢?其中能抱住的柱子里面最粗的柱子又有多粗呢? 注意:假设柱子的截面为一个正圆形,臂展不小于其周长才能将其完全抱住。

Input
第1行一个整数,表示小朋友的臂展([1,700])。第2行10个整数,表示每根柱子的半径。(半径在[1,100]之间)

Output
输出2个整数A、B,以空格分隔。 A表示小朋友能完全抱住的柱子有几根。 B表示能抱住的柱子的最大半径,如果没柱子可抱则B为-1。

Sample Input
100
6 7 8 9 10 5 2 4 7 5 

Sample Output
10 10

HINT
圆周率取3.14

Source
NBU OJ
#include<stdio.h>
void main()
{
	int n,i=1,m=0,s;
	int a=0;
	scanf("%d",&s);
	while(i<=10)
	{scanf("%d",&n);
	if(2*3.14*n<=s)
	{a++;
	if(n>m)
		m=n;}
	i++;}
	if(a>0)
		printf("%d %d\n",a,m);
	else
		printf("%d %d\n",a,-1);
}

  • 26
    点赞
  • 108
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
06-01
这道题是一道典型的费用限制最短路题目,可以使用 Dijkstra 算法或者 SPFA 算法来解决。 具体思路如下: 1. 首先,我们需要读入输入数据。输入数据中包含了道路的数量、起点和终点,以及每条道路的起点、终点、长度和限制费用。 2. 接着,我们需要使用邻接表或邻接矩阵来存储图的信息。对于每条道路,我们可以将其起点和终点作为一个有向边的起点和终点,长度作为边权,限制费用作为边权的上界。 3. 然后,我们可以使用 Dijkstra 算法或 SPFA 算法求解从起点到终点的最短路径。在这个过程中,我们需要记录到每个点的最小费用和最小长度,以及更新每条边的最小费用和最小长度。 4. 最后,我们输出从起点到终点的最短路径长度即可。 需要注意的是,在使用 Dijkstra 算法或 SPFA 算法时,需要对每个点的最小费用和最小长度进行松弛操作。具体来说,当我们从一个点 u 经过一条边 (u,v) 到达另一个点 v 时,如果新的费用和长度比原来的小,则需要更新到达 v 的最小费用和最小长度,并将 v 加入到优先队列(Dijkstra 算法)或队列(SPFA 算法)中。 此外,还需要注意处理边权为 0 或负数的情况,以及处理无法到达终点的情况。 代码实现可以参考以下样例代码: ```c++ #include <cstdio> #include <cstring> #include <queue> #include <vector> using namespace std; const int MAXN = 1005, MAXM = 20005, INF = 0x3f3f3f3f; int n, m, s, t, cnt; int head[MAXN], dis[MAXN], vis[MAXN]; struct Edge { int v, w, c, nxt; } e[MAXM]; void addEdge(int u, int v, int w, int c) { e[++cnt].v = v, e[cnt].w = w, e[cnt].c = c, e[cnt].nxt = head[u], head[u] = cnt; } void dijkstra() { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; memset(dis, 0x3f, sizeof(dis)); memset(vis, 0, sizeof(vis)); dis[s] = 0; q.push(make_pair(0, s)); while (!q.empty()) { int u = q.top().second; q.pop(); if (vis[u]) continue; vis[u] = 1; for (int i = head[u]; i != -1; i = e[i].nxt) { int v = e[i].v, w = e[i].w, c = e[i].c; if (dis[u] + w < dis[v] && c >= dis[u] + w) { dis[v] = dis[u] + w; q.push(make_pair(dis[v], v)); } } } } int main() { memset(head, -1, sizeof(head)); scanf("%d %d %d %d", &n, &m, &s, &t); for (int i = 1; i <= m; i++) { int u, v, w, c; scanf("%d %d %d %d", &u, &v, &w, &c); addEdge(u, v, w, c); addEdge(v, u, w, c); } dijkstra(); if (dis[t] == INF) printf("-1\n"); else printf("%d\n", dis[t]); return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前进的咸鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值