1、 选修课考试作业2012 素数判定 .332014 青年歌手大奖赛_评委会打分 342017 字符串统计402019 数列有序! .412020 绝对值排序 .432033 人见人爱 A+B462039 三角形 .482040 亲和数 .49姓名:春杰级:电商 141001 Sum ProblemProblem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + . + n.
2、InputThe input will consist of a series of integers n, one integer per line.OutputFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.Sample Input1100Sample Output15050AuthorDOOM III解答:#includemain()int n,i,sum;s
3、um=0;while(scanf(“%d“,for(i=0;imain()int a,b;while(scanf(“%d%d“,1090 A+B for Input-Output Practice (II)Problem DescriptionYour task is to Calculate a + b.InputInput contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a spac
4、e, one pair of integers per line. OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input. Sample Input21 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include#define M 1000void main() int a ,b,n,jM,i;/
5、printf(“please input n:n“);scanf(“%d“,for(i=0;imain()int a,b;scanf(“%d %d“,while(!(a=0scanf(“%d %d“,1092 A+B for Input-Output Practice (IV)Problem DescriptionYour task is to Calculate the sum of some integers.InputInput contains multiple test cases. Each test case contains a integer N, and then N in
6、tegers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input. Sample Input4 1 2 3 45 1 2 3 4 50 Sample Outp
7、ut1015AuthorlcyRecommendJGShining解答:#include int main()int n,sum,i,t;while(scanf(“%d“,for(i=0;imain()int n,a,b,i,j,sum;sum=0;while(scanf(“%dn“,imain()int n,a,b,i,j,sum;sum=0;while(scanf(“%dn“,jmain()int a,b;while(scanf(“%d%d“,1096 A+B for Input-Output Practice (VIII)Problem DescriptionYour task is t
8、o calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line. OutputFor each group of input integers you should output their sum in one line, and you must note that the
9、re is a blank line between outputs.Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3Sample Output10156AuthorlcyRecommendJGShining解答:int main()int a,b,i,j,l1000,k;scanf(“%d“,getchar();for(j=1;jmain()char a,b,c,d;while(scanf(“%c %c %c“,if(a=b)if(c=a)printf(“%c %c %cn“,b,a,c);else if(b=c)printf(“%c %c %cn“,c,b,
10、a);else if(b=b)printf(“%c %c %cn“,a,b,c);else if(c=a)printf(“%c %c %cn“,a,c,b);else if(ac)printf(“%c %c %cn“,c,a,b);2001 计算两点间的距离Problem Description输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。Input输入数据有多组,每组占一行,由 4 个实数组成,分别表示 x1,y1,x2,y2,数据之间用空格隔开。Output对于每组输入数据,输出一行,结果保留两位小数。Sample Input0 0 0 10 1 1 0Sample
11、Output1.001.41AuthorlcySourceC 语言程序设计练习(一) RecommendJGShining解答:#include#includemain()double a,b,c,d,s;while(scanf(“%lf %lf %lf %lf“,printf(“%.2lfn“,s); 2002 计算球体积Problem Description根据输入的半径值,计算球的体积。Input输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。Output输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。Sample Input11.5Sample Out
12、put4.18914.137Hint#define PI 3.1415927AuthorlcySourceC 语言程序设计练习(一) RecommendJGShining解答:#include#define PI 3.1415927main()double a,v;while(scanf(“%lf“,printf(“%.3lfn“,v); 2003 求绝对值Problem Description求实数的绝对值。Input输入数据有多组,每组占一行,每行包含一个实数。Output对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。Sample Input123-234.00
13、Sample Output123.00234.00AuthorlcySourceC 语言程序设计练习(一) RecommendJGShining解答:#includemain()double a;while(scanf(“%lf“,while(scanf(“%d“,else if(n=80)printf(“Bn“);else if(n=70)printf(“Cn“);else if(n=60)printf(“Dn“);else printf(“En“); return 0;2005 第几天?Problem Description给定一个日期,输出这个日期是该年的第几天。Input输入数据有多组
14、,每组占一行,数据格式为 YYYY/MM/DD 组成,具体参见 sample input ,另外,可以向你确保所有的输入数据是合法的。Output对于每组输入数据,输出一行,表示该日期是该年的第几天。Sample Input1985/1/202006/3/12Sample Output2071AuthorlcySourceC 语言程序设计练习(一) RecommendJGShining解答:#includemain()int a,b,c,d,e,f,g;while(scanf(“%d/%d/%d“,else if(b=2)d=31+c;else if(b=3)d=31+28+c;else if
15、(b=4)d=31+28+31+c;else if(b=5)d=31+31+28+30+c;else if(b=6)d=31+28+31+30+31+c;else if(b=7)d=31+28+31+30+31+30+c;else if(b=8)d=31+28+31+30+31+30+31+c;else if(b=9)d=31+28+31+30+31+30+31+31+c;else if(b=10)d=31+28+31+30+31+30+31+31+30+c;else if(b=11)d=31+28+31+30+31+30+31+31+30+31+c;else if(b=12)d=31+28+
16、31+30+31+30+31+31+30+31+c+30;e=a%100;f=a%400;g=a%4;if(e=0)if(f=0)d=1+d;elsed=d;else if(g=0)d=d+1;elsed=d;printf(“%dn“,d);2006 求奇数的乘积Problem Description给你 n 个整数,求他们中所有奇数的乘积。Input输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为 n,表示本组数据一共有 n 个,接着是 n 个整数,你可以假设每组数据必定至少存在一个奇数。Output输出每组数中的所有奇数的乘积,对于测试实例,输出一行。Sample Input
17、3 1 2 34 2 3 4 5Sample Output315AuthorlcySourceC 语言程序设计练习(一) RecommendJGShining解答:#includemain()int n,s,i,a;while(scanf(“%d“,for(i=0;iint main()int sum1,sum2,n,i,m,t;while(scanf(“%d%d“,if(mn)t=m;m=n;n=t;for(i=m;iint main()int n,i,b1,b2,b3;double a101;while(scanf(“%d“,in;i+) scanf(“%lf“,b1=b2=b3=0;fo
18、r(i=0;in;i+)if(ai0) b1+;else if(ai=0) b2+;else b3+;printf(“%d %d %dn“,b1,b2,b3);2009 求数列的和Problem Description数列的定义如下:数列的第一项为 n,以后各项为前一项的平方根,求数列的前 m 项的和。Input输入数据有多组,每组占一行,由两个整数 n(n10000)和 m(m1000)组成,n 和 m 的含义如前所述。Output对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留 2 位小数。Sample Input81 42 2Sample Output94.733.41Authorlcy