




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、文檔可能無法思考全面,請瀏覽后下載! Acm試題及答案1001 Sum Problem21089 A+B for Input-Output Practice (I)41090 A+B for Input-Output Practice (II)61091 A+B for Input-Output Practice (III)81092 A+B for Input-Output Practice (IV)91093 A+B for Input-Output Practice (V)111094 A+B for Input-Output Practice (VI)121095 A+B for In
2、put-Output Practice (VII)131096 A+B for Input-Output Practice (VIII)142000 ASCII碼排序162001計算兩點間的距離172002計算球體積192003求絕對值202004成績轉(zhuǎn)換212005第幾天?222006求奇數(shù)的乘積242007平方和與立方和262008數(shù)值統(tǒng)計272009求數(shù)列的和282010水仙花數(shù)292011多項式求和312012素數(shù)判定332014青年歌手大獎賽_評委會打分342015偶數(shù)求和362016數(shù)據(jù)的交換輸出382017字符串統(tǒng)計402019數(shù)列有序!412020絕對值排序432021發(fā)工資咯
3、:)452033人見人愛A+B462039三角形482040親和數(shù)4951 / 521001 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. InputThe input will consist of a series of integers n, one integer per line. Out
4、putFor 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 Input1100 Sample Output15050 AuthorDOOM III解答:#include<stdio.h>main() int n,i,sum; sum=0; while(scanf("%d",&n)!=-1
5、) sum=0; for(i=0;i<=n;i+) sum+=i; printf("%dnn",sum); 1089 A+B for Input-Output Practice (I)Problem DescriptionYour task is to Calculate a + b.Too easy?! Of course! I specially designed the problem for acm beginners. You must have found that some problems have the same titles with this
6、one, yes, all these problems were designed for the same aim. InputThe input will consist of a series of pairs of integers a and b, separated by a space, 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
7、 one line of output for each line in input. Sample Input1 510 20 Sample Output630 Authorlcy RecommendJGShining解答:#include<stdio.h> main() int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%dn",a+b); 1090 A+B for Input-Output Practice (II)Problem
8、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 space, one pair of integers per line. OutputFor each pair of input integers a and b you should output t
9、he sum of a and b in one line, and with one line of output for each line in input. Sample Input21 510 20 Sample Output630 Authorlcy RecommendJGShining解答:#include<stdio.h>#define M 1000void main() int a ,b,n,jM,i; /printf("please input n:n"); scanf("%d",
10、&n); for(i=0;i<n;i+) scanf("%d%d",&a,&b); /printf("%d %d",a,b); ji=a+b; i=0; while(i<n) printf("%d",ji); i+; printf("n"); 1091 A+B for Input-Output Practice (III)Problem DescriptionYour task is to Calculate a + b.InputInput contains multiple
11、test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.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 o
12、f output for each line in input. Sample Input1 510 200 0Sample Output630 AuthorlcyRecommendJGShining解答:#include<stdio.h> main() int a,b; scanf("%d %d",&a,&b); while(!(a=0&&b=0) printf("%dn",a+b); scanf("%d %d",&a,&b); 1092 A+B for Inpu
13、t-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 integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to b
14、e 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 Output1015 Authorlcy RecommendJGShining 解答:#include <stdio.h>int main() int
15、n,sum,i,t; while(scanf("%d",&n)!=EOF&&n!=0) sum=0; for(i=0;i<n;i+) scanf("%d",&t); sum=sum+t; printf("%dn",sum); 1093 A+B for Input-Output Practice (V)Problem DescriptionYour task is to calculate the sum of some integers. InputInput contains an i
16、nteger 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 with one line of output for each line in input. Sample Input24 1 2 3 45 1 2 3
17、 4 5 Sample Output1015 Authorlcy解答:#include<stdio.h>main() int n,a,b,i,j,sum; sum=0; while(scanf("%dn",&n)!=-1) for(i=0;i<n;i+) scanf("%d",&b); for(j=0;j<b;j+) scanf("%d",&a); sum+=a; printf("%dn",sum); sum=0; 1094 A+B for Inp
18、ut-Output Practice (VI)Problem DescriptionYour task is to calculate the sum of some integers. InputInput contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line. OutputFor each test case you should output the sum
19、 of N integers in one line, and with one line of output for each line in input. Sample Input4 1 2 3 45 1 2 3 4 5 Sample Output1015 Authorlcy RecommendJGShining解答:#include<stdio.h>main() int n,a,b,i,j,sum; sum=0; while(scanf("%dn",&n)!=-1) for(j=0;j<n;j+) s
20、canf("%d",&a); sum+=a; printf("%dn",sum); sum=0; 1095 A+B for Input-Output Practice (VII)Problem DescriptionYour task is to Calculate a + b. InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line. O
21、utputFor each pair of input integers a and b you should output the sum of a and b, and followed by a blank line. Sample Input1 510 20 Sample Output630 Authorlcy RecommendJGShining解答:#include<stdio.h> main() int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf(
22、"%dnn",a+b); 1096 A+B for Input-Output Practice (VIII)Problem DescriptionYour task is to 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.
23、60;OutputFor each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs. Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3 Sample Output10156 Authorlcy RecommendJGShining解答:int main() int a,b,i,j,l1000,k; scanf("
24、%d",&i); getchar(); for(j=1;j<=i;j+) lj=0; for(j=1;j<=i;j+) scanf("%d",&a); getchar(); for(k=1;k<=a;k+) scanf("%d",&b); getchar(); lj+=b; for(j=1;j<=i-1;j+) printf("%dnn",lj); printf("%dn",li); 2000 ASCII碼排序Problem Description輸入三個字
25、符后,按各字符的ASCII碼從小到大的順序輸出這三個字符。 Input輸入數(shù)據(jù)有多組,每組占一行,有三個字符組成,之間無空格。 Output對于每組輸入數(shù)據(jù),輸出一行,字符中間用一個空格分開。 Sample Inputqweasdzxc Sample Outpute q wa d sc x z Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining解答:#include<stdio.h>main() char a,b,c,d; while(scanf("%c %
26、c %c",&a,&b,&c)!=EOF) getchar(); if(a>=b) if(c>=a) printf("%c %c %cn",b,a,c); else if(b>=c) printf("%c %c %cn",c,b,a); else if(b<c) printf("%c %c %cn",b,c,a); else if(c>=b) printf("%c %c %cn",a,b,c); else if(c>=a) printf(&quo
27、t;%c %c %cn",a,c,b); else if(a>c) printf("%c %c %cn",c,a,b); 2001計算兩點間的距離Problem Description輸入兩點坐標(biāo)(X1,Y1),(X2,Y2),計算并輸出兩點間的距離。 Input輸入數(shù)據(jù)有多組,每組占一行,由4個實數(shù)組成,分別表示x1,y1,x2,y2,數(shù)據(jù)之間用空格隔開。 Output對于每組輸入數(shù)據(jù),輸出一行,結(jié)果保留兩位小數(shù)。 Sample Input0 0 0 10 1 1 0 Sample Output1.001.41
28、60;Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining 解答:#include<stdio.h>#include<math.h>main() double a,b,c,d,s; while(scanf("%lf %lf %lf %lf",&a,&b,&c,&d)!=EOF) s=sqrt(a-c)*(a-c)+(b-d)*(b-d); printf("%.2lfn",s); 2002計算球體積Problem Descrip
29、tion根據(jù)輸入的半徑值,計算球的體積。 Input輸入數(shù)據(jù)有多組,每組占一行,每行包括一個實數(shù),表示球的半徑。 Output輸出對應(yīng)的球的體積,對于每組輸入數(shù)據(jù),輸出一行,計算結(jié)果保留三位小數(shù)。 Sample Input11.5 Sample Output4.18914.137Hint#define PI 3.1415927 Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining解答:#include<stdio.h>#define PI 3.1415927main()
30、 double a,v; while(scanf("%lf",&a)!=EOF) v=4*PI*a*a*a/3; printf("%.3lfn",v); 2003求絕對值Problem Description求實數(shù)的絕對值。 Input輸入數(shù)據(jù)有多組,每組占一行,每行包含一個實數(shù)。 Output對于每組輸入數(shù)據(jù),輸出它的絕對值,要求每組數(shù)據(jù)輸出一行,結(jié)果保留兩位小數(shù)。 Sample Input123-234.00 Sample Output123.00234.00 Authorlcy S
31、ourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining解答:#include<stdio.h>main() double a; while(scanf("%lf",&a)!=EOF) if(a<0) a=-a; printf("%.2lfn",a); 2004成績轉(zhuǎn)換Problem Description輸入一個百分制的成績t,將其轉(zhuǎn)換成對應(yīng)的等級,具體轉(zhuǎn)換規(guī)則如下:90100為A;8089為B;7079為C;6069為D;059為E; Input輸入數(shù)據(jù)有多組,每組占一行,由一個整數(shù)組成
32、。 Output對于每組輸入數(shù)據(jù),輸出一行。如果輸入數(shù)據(jù)不在0100范圍內(nèi),請輸出一行:“Score is error!”。 Sample Input5667100123 Sample OutputEDAScore is error! Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining解答:#include <stdio.h>int main() int n; while(scanf("%d",&n)!=EOF) if(n>100|n<0
33、)printf("Score is error!n"); else if(n>=90)printf("An"); 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
34、輸入數(shù)據(jù)有多組,每組占一行,數(shù)據(jù)格式為YYYY/MM/DD組成,具體參見sample input ,另外,可以向你確保所有的輸入數(shù)據(jù)是合法的。 Output對于每組輸入數(shù)據(jù),輸出一行,表示該日期是該年的第幾天。 Sample Input1985/1/202006/3/12 Sample Output2071 Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining解答:#include<stdio.h>main() int a,b,c,d,e,f,g; while(scanf(&qu
35、ot;%d/%d/%d",&a,&b,&c)!=EOF) if(b=1) d=c; else if(b=2) d=31+c; else if(b=3) d=31+28+c; else if(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+3
36、0+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+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; else d=d; else if(g=0) d=d+1; else d=d; printf("%dn",d); 2006求奇數(shù)的乘積Problem Descripti
37、on給你n個整數(shù),求他們中所有奇數(shù)的乘積。 Input輸入數(shù)據(jù)包含多個測試實例,每個測試實例占一行,每行的第一個數(shù)為n,表示本組數(shù)據(jù)一共有n個,接著是n個整數(shù),你可以假設(shè)每組數(shù)據(jù)必定至少存在一個奇數(shù)。 Output輸出每組數(shù)中的所有奇數(shù)的乘積,對于測試實例,輸出一行。 Sample Input3 1 2 34 2 3 4 5 Sample Output315 Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining解答:#include<stdio.h>main() int
38、 n,s,i,a; while(scanf("%d",&n)!=EOF) s=1; for(i=0;i<n;i+) scanf("%d",&a); if(a%2=1) s=s*a; else ; printf("%dn",s); 2007平方和與立方和Problem Description給定一段連續(xù)的整數(shù),求出他們中所有偶數(shù)的平方和以及所有奇數(shù)的立方和。 Input輸入數(shù)據(jù)包含多組測試實例,每組測試實例包含一行,由兩個整數(shù)m和n組成。 Output對于每組輸入數(shù)據(jù),輸出一行,應(yīng)包括兩個整數(shù)x
39、和y,分別表示該段連續(xù)的整數(shù)中所有偶數(shù)的平方和以及所有奇數(shù)的立方和。你可以認(rèn)為32位整數(shù)足以保存結(jié)果。 Sample Input1 32 5 Sample Output4 2820 152 Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJGShining解答:#include<stdio.h>int main() int sum1,sum2,n,i,m,t; while(scanf("%d%d",&m,&n)!=EOF) sum1=sum2=0; if(m>n
40、)t=m;m=n;n=t; for(i=m;i<=n;i+) if(i%2=0) sum1+=(i*i); else sum2+=(i*i*i); printf("%d %dn",sum1,sum2); return 0;2008數(shù)值統(tǒng)計Problem Description統(tǒng)計給定的n個數(shù)中,負(fù)數(shù)、零和正數(shù)的個數(shù)。 Input輸入數(shù)據(jù)有多組,每組占一行,每行的第一個數(shù)是整數(shù)n(n<100),表示需要統(tǒng)計的數(shù)值的個數(shù),然后是n個實數(shù);如果n=0,則表示輸入結(jié)束,該行不做處理。 Output對于每組輸入數(shù)據(jù),輸出一行a,b和c,分別表示給定的數(shù)
41、據(jù)中負(fù)數(shù)、零和正數(shù)的個數(shù)。 Sample Input6 0 1 2 3 -1 05 1 2 3 4 0.50 Sample Output1 2 30 0 5 Authorlcy SourceC語言程序設(shè)計練習(xí)(二) RecommendJGShining解答:#include<stdio.h>int main() int n,i,b1,b2,b3; double a101; while(scanf("%d",&n)!=EOF && n!=0) for(i=0;i<n;i+) sca
42、nf("%lf",&ai); b1=b2=b3=0; for(i=0;i<n;i+) if(ai<0) b1+; else if(ai=0) b2+; else b3+; printf("%d %d %dn",b1,b2,b3); 2009求數(shù)列的和Problem Description數(shù)列的定義如下:數(shù)列的第一項為n,以后各項為前一項的平方根,求數(shù)列的前m項的和。 Input輸入數(shù)據(jù)有多組,每組占一行,由兩個整數(shù)n(n<10000)和m(m<1000)組成,n和m的含義如前所述。 Output對于每組
43、輸入數(shù)據(jù),輸出該數(shù)列的和,每個測試實例占一行,要求精度保留2位小數(shù)。 Sample Input81 42 2 Sample Output94.733.41 Authorlcy SourceC語言程序設(shè)計練習(xí)(二) RecommendJGShining解答:#include<stdio.h>#include<math.h>main() double n,m,s,w,i; while(scanf("%lf%lf",&n,&m)!=EOF) s=n; for(i=1;i<m;i+)
44、n=sqrt(n); s=s+n; printf("%.2lfn",s); 2010水仙花數(shù)Problem Description春天是鮮花的季節(jié),水仙花就是其中最迷人的代表,數(shù)學(xué)上有個水仙花數(shù),他是這樣定義的:“水仙花數(shù)”是指一個三位數(shù),它的各位數(shù)字的立方和等于其本身,比如:153=13+53+33?,F(xiàn)在要求輸出所有在m和n范圍內(nèi)的水仙花數(shù)。 Input輸入數(shù)據(jù)有多組,每組占一行,包括兩個整數(shù)m和n(100<=m<=n<=999)。 Output對于每個測試實例,要求輸出所有在給定范圍內(nèi)的水仙花數(shù),就是說,輸出的水仙花數(shù)必須大于等于m
45、,并且小于等于n,如果有多個,則要求從小到大排列在一行內(nèi)輸出,之間用一個空格隔開;如果給定的范圍內(nèi)不存在水仙花數(shù),則輸出no;每個測試實例的輸出占一行。 Sample Input100 120300 380 Sample Outputno370 371 Authorlcy SourceC語言程序設(shè)計練習(xí)(二) RecommendJGShining解答:#include<stdio.h>main() int m,n,i,w,a,b,c,j,s,d; while(scanf("%d %d",&n,&
46、m)!=EOF) d=0; j=1; if(m>n) w=m; m=n; n=w; else ; for(i=m;i<=n;i+) a=i/100; b=i/10%10; c=i%10; s=a*a*a+b*b*b+c*c*c; if(i=s) if(d!=0) printf(" "); printf("%d",i); d=d+1; j=j+1; if(j=1) printf("non"); else printf("n"); 2011多項式求和Problem Description多項式的描述如下:1
47、 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + .現(xiàn)在請你求出該多項式的前n項的和。 Input輸入數(shù)據(jù)由2行組成,首先是一個正整數(shù)m(m<100),表示測試實例的個數(shù),第二行包含m個正整數(shù),對于每一個整數(shù)(不妨設(shè)為n,n<1000),求該多項式的前n項的和。 Output對于每個測試實例n,要求輸出多項式前n項的和。每個測試實例的輸出占一行,結(jié)果保留2位小數(shù)。 Sample Input21 2 Sample Output1.000.50 Authorlcy SourceC語言程序設(shè)計練習(xí)(二)
48、0;RecommendJGShining解答:#include<stdio.h>#include<math.h>main() double m,n,i,s,j,k,a; while(scanf("%lf",&m)!=EOF) for(i=0;i<m;i+) s=0; scanf("%lf",&n); for(j=1;j<=n;j+) s=s+1/j*pow(-1,j+1); printf("%.2lfn",s); 2012素數(shù)判定Problem Description對于表達式n2+
49、n+41,當(dāng)n在(x,y)范圍內(nèi)取整數(shù)值時(包括x,y)(-39<=x<y<=50),判定該表達式的值是否都為素數(shù)。 Input輸入數(shù)據(jù)有多組,每組占一行,由兩個整數(shù)x,y組成,當(dāng)x=0,y=0時,表示輸入結(jié)束,該行不做處理。 Output對于每個給定范圍內(nèi)的取值,如果表達式的值都為素數(shù),則輸出"OK",否則請輸出“Sorry”,每組輸出占一行。 Sample Input0 10 0 Sample OutputOK Authorlcy SourceC語言程序設(shè)計練習(xí)(二) Recomm
50、endJGShining解答:#include<stdio.h>main() int x,y,i,j,s,k,w,d; while(scanf("%d%d",&x,&y)=2&&(x!=0|y!=0) w=0; for(i=x;i<=y;i+) k=i*i+i+41; for(j=2;j<k;j+) d=k%j; if(d=0) w+; if(w=0) printf("OKn"); else printf("Sorryn"); 2014青年歌手大獎賽_評委會打分Problem Description青年歌手大獎賽中,評委會給參賽選手打分。選手得分規(guī)則為去掉一個最高分和一個最低分,然后計算平均得分,請編程輸出某選手的得分。 Input輸入數(shù)據(jù)有多組,每組占一行,每行的第一個數(shù)是n(2<n<100),表示評委的人數(shù),然后是n個評委的打分。 Output對于每組輸入數(shù)據(jù),輸出選手的得分,結(jié)果保留2位小數(shù),每組輸出占一行。 Sam
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 ISO/TR 8955:2025 EN Railway infrastructure - Track quality evaluation - Chord-based method
- 消費金融公司的市場調(diào)研與需求分析考核試卷
- 海底油氣管道新型鋪設(shè)技術(shù)考核試卷
- 煤氣化中的清潔生產(chǎn)工藝優(yōu)化研究考核試卷
- 水產(chǎn)加工企業(yè)發(fā)展戰(zhàn)略規(guī)劃與實施考核試卷
- 數(shù)字出版物的版權(quán)侵權(quán)案例分析考核試卷
- 期貨市場風(fēng)險管理工具比較服務(wù)考核試卷
- 果品、蔬菜種植氣候智慧型農(nóng)業(yè)考核試卷
- 上海代辦租房合同標(biāo)準(zhǔn)文本
- 為企業(yè)安裝合同標(biāo)準(zhǔn)文本
- 2022-2023學(xué)年高中政治統(tǒng)編版選擇性必修二5-1家和萬事興 第1課時 學(xué)案
- 土的擊實試驗JTG34302020
- 大氣污染防治與總量減排
- 引風(fēng)機檢修工藝規(guī)程
- GB/T 3836.9-2021爆炸性環(huán)境第9部分:由澆封型“m”保護的設(shè)備
- GB/T 20001.4-2015標(biāo)準(zhǔn)編寫規(guī)則第4部分:試驗方法標(biāo)準(zhǔn)
- GB/T 19666-2005阻燃和耐火電線電纜通則
- GB/T 18316-2001數(shù)字測繪產(chǎn)品檢查驗收規(guī)定和質(zhì)量評定
- 脊柱損傷固定搬運術(shù)課件整理
- 代發(fā)貨合作協(xié)議范本2023
- 稅收風(fēng)險管理課件
評論
0/150
提交評論