Problem Description春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。现在要求输出所有在m和n范围内的水仙花数。Input输入数据有多组,每组占一行,包括两个整数m和n(100 2 #include 3 bool is_shuixianhua(int n) 4 { 5 if((int)(pow(n%10,3)+pow(n/10%10,3)+pow(n/100,3))==n) 6 return true; 7 return ... Read More
posted @ 2013-06-15 22:55 瓶哥 Views(224) Comments(0) Diggs(0) Edit
Problem Description统计给定的n个数中,负数、零和正数的个数。Input输入数据有多组,每组占一行,每行的第一个数是整数n(n 2 int main() 3 { 4 int n; 5 double num; 6 while(~scanf("%d",&n)&&n!=0) 7 { 8 int ans[3]={0}; 9 for(int i=0;i0)17 ans[2]++; 18 }19 printf("%d %d %d\n",ans[... Read More
posted @ 2013-06-15 22:54 瓶哥 Views(187) Comments(0) Diggs(0) Edit
Problem Description数列的定义如下:数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。Input输入数据有多组,每组占一行,由两个整数n(n 2 #include 3 int main() 4 { 5 int n,m; 6 while(~scanf("%d %d",&n,&m)) 7 { 8 double ans=n,f=n; 9 for(int i=1;i<m;i++)10 {11 f=sqrt(f);12 ans=... Read More
posted @ 2013-06-15 22:54 瓶哥 Views(689) Comments(0) Diggs(0) Edit
Problem Description给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。Input输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。Output对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。你可以认为32位整数足以保存结果。Sample Input1 3 2 5Sample Output4 28 20 152 1 #include 2 int main() 3 { 4 int m,n; 5 while(~scanf("%d %d",&m,& Read More
posted @ 2013-06-15 22:53 瓶哥 Views(194) Comments(0) Diggs(0) Edit
Problem Description给你n个整数,求他们中所有奇数的乘积。Input输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。Output输出每组数中的所有奇数的乘积,对于测试实例,输出一行。Sample Input3 1 2 3 4 2 3 4 5Sample Output3 15 1 #include 2 int main() 3 { 4 int n,num; 5 while(~scanf("%d",&n)) 6 { 7 unsigned a... Read More
posted @ 2013-06-15 22:52 瓶哥 Views(341) Comments(0) Diggs(0) Edit
Problem Description给定一个日期,输出这个日期是该年的第几天。Input输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。Output对于每组输入数据,输出一行,表示该日期是该年的第几天。Sample Input1985/1/20 2006/3/12Sample Output20 71 1 #include 2 #include 3 const int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; 4 bool is_leapyea.. Read More
posted @ 2013-06-15 21:45 瓶哥 Views(181) Comments(0) Diggs(0) Edit
Problem Description输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:90~100为A;80~89为B;70~79为C;60~69为D;0~59为E;Input输入数据有多组,每组占一行,由一个整数组成。Output对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。Sample Input56 67 100 123Sample OutputE D A Score is error! 1 #include 2 int main() 3 { 4 int score; 5 char ch; 6 ... Read More
posted @ 2013-06-15 21:44 瓶哥 Views(206) Comments(0) Diggs(0) Edit
Problem Description求实数的绝对值。Input输入数据有多组,每组占一行,每行包含一个实数。Output对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。Sample Input123 -234.00Sample Output123.00 234.00 1 #include 2 int main() 3 { 4 double n; 5 while(~scanf("%lf",&n)) 6 { 7 if(n<0) 8 n=-1*n; 9 printf("%.2lf\n",... Read More
posted @ 2013-06-15 21:43 瓶哥 Views(364) Comments(0) Diggs(0) Edit
Problem Description根据输入的半径值,计算球的体积。Input输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。Output输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。Sample Input1 1.5Sample Output4.189 14.137Hint#define PI 3.1415927 1 #include 2 #define PI 3.1415927 3 int main() 4 { 5 double r; 6 while(~scanf("%lf",&r)) 7 { 8 print... Read More
posted @ 2013-06-15 21:06 瓶哥 Views(219) Comments(0) Diggs(0) Edit
Problem Description输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。Input输入数据有多组,每组占一行,有三个字符组成,之间无空格。Output对于每组输入数据,输出一行,字符中间用一个空格分开。Sample Inputqwe asd zxcSample Outpute q w a d s c x z 1 #include 2 #include 3 using namespace std; 4 bool cmp(char a,char b) 5 { 6 return a<b; 7 } 8 int main() 9 {10 char ... Read More
posted @ 2013-06-15 21:05 瓶哥 Views(245) Comments(0) Diggs(0) Edit