杭電ACM水題題目及代碼_第1頁
杭電ACM水題題目及代碼_第2頁
杭電ACM水題題目及代碼_第3頁
杭電ACM水題題目及代碼_第4頁
杭電ACM水題題目及代碼_第5頁
已閱讀5頁,還剩70頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、1002 A + B Problem IITime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 69615    Accepted Submission(s): 12678Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is

2、to calculate the Sum of A + B. InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them

3、by using 32-bit integer. You may assume the length of each integer will not exceed 1000. OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the r

4、esult of A + B. Note there are some spaces int the equation. Output a blank line between two test cases. Sample Input21 2 Sample OutputCase 1:1 + 2 = 3Case 2: AuthorIgnatius.L#include <stdio.h>#include <string.h>int main()char str11001, str21001;int t, i, len_str1, len_str

5、2, len_max, num = 1, k;scanf("%d", &t);getchar();while(t-)int a1001 = 0, b1001 = 0, c1001 = 0;scanf("%s", str1);len_str1 = strlen(str1);for(i = 0; i <= len_str1 - 1; +i)ai = str1len_str1 - 1 - i - '0'scanf("%s",str2);len_str2 = strlen(str2);for(i = 0; i &

6、lt;= len_str2 - 1; +i)bi = str2len_str2 - 1 - i - '0'if(len_str1 > len_str2)len_max = len_str1;elselen_max = len_str2;k = 0;for(i = 0; i <= len_max - 1; +i)ci = (ai + bi + k) % 10;k = (ai + bi + k) / 10;if(k != 0)clen_max = 1;printf("Case %d:n", num);num+;printf("%s + %s

7、 = ", str1, str2);if(clen_max = 1)printf("1");for(i = len_max - 1; i >= 0; -i)printf("%d", ci);printf("n");if(t >= 1)printf("n");return 0;成績轉(zhuǎn)換Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25250

8、Accepted Submission(s): 10776Problem Description輸入一個百分制的成績t,將其轉(zhuǎn)換成對應(yīng)的等級,具體轉(zhuǎn)換規(guī)則如下:90100為A;8089為B;7079為C;6069為D;059為E; Input輸入數(shù)據(jù)有多組,每組占一行,由一個整數(shù)組成。 Output對于每組輸入數(shù)據(jù),輸出一行。如果輸入數(shù)據(jù)不在0100范圍內(nèi),請輸出一行:“Score is error!”。 Sample Input5667100123 Sample OutputEDAScore is error! Authorlcy SourceC語言程序設(shè)計練習(xí)(一) RecommendJG

9、Shining#include <stdio.h>int main() int n, k; while(scanf("%d", &n) != EOF) if(n < 0 | n >100) printf("Score is error!n"); else k = n / 10; switch(k) case 10: printf("An"); break; case 9: printf("An"); break; case 8: printf("Bn"); bre

10、ak; case 7: printf("Cn"); break; case 6: printf("Dn"); break; default: printf("En"); break; return 0;2007平方和與立方和Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 65   Accepted Submission(s

11、) : 9Font: Times New Roman | Verdana | GeorgiaFont Size:  Problem Description給定一段連續(xù)的整數(shù),求出他們中所有偶數(shù)的平方和以及所有奇數(shù)的立方和。Input輸入數(shù)據(jù)包含多組測試實例,每組測試實例包含一行,由兩個整數(shù)m和n組成。Output對于每組輸入數(shù)據(jù),輸出一行,應(yīng)包括兩個整數(shù)x和y,分別表示該段連續(xù)的整數(shù)中所有偶數(shù)的平方和以及所有奇數(shù)的立方和。你可以認(rèn)為32位整數(shù)足以保存結(jié)果。Sample Input1 32 5Sample Output4 28

12、20 152AuthorlcySourceC語言程序設(shè)計練習(xí)(一)Statistic | #include <stdio.h>int main() int x , y, temp, sum1, sum2; while(scanf("%d %d", &x, &y) != EOF) sum1 = 0; sum2 = 0; if(x > y) temp = x; x = y; y = temp; for(; x <= y; x+) if( x % 2 = 0) sum1 += x * x; else sum2 += x

13、* x * x; printf("%d %dn", sum1, sum2); return 0;2010水仙花數(shù)Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 144   Accepted Submission(s) : 27Font: Times New Roman | Verdana | GeorgiaFon

14、t Size:  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,并且小于等于n,如果有多個,則要求從小到大排列在一行內(nèi)輸出,之間用一個空格隔開;如果給定的范圍內(nèi)

15、不存在水仙花數(shù),則輸出no;每個測試實例的輸出占一行。Sample Input100 120300 380Sample Outputno370 371AuthorlcySourceC語言程序設(shè)計練習(xí)(二)#include <stdio.h>int main() int m, n, k1, k2, k3, count; while(scanf("%d %d", &m, &n) != EOF) for(count = 0; m <= n; +m) k1 = m / 100; k2 = (m - 100 * k1) / 10; k3 = (m -

16、100 * k1 -10 * k2); if(m = k1*k1*k1 + k2*k2*k2 + k3*k3*k3) if(count != 0) printf(" "); printf("%d", m); count+; if(count = 0) printf("non"); else printf("n"); return 0;2012 素數(shù)判定Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K

17、(Java/Other)Total Submission(s) : 29   Accepted Submission(s) : 15Font: Times New Roman | Verdana | GeorgiaFont Size:  Problem Description對于表達式n2+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=

18、0時,表示輸入結(jié)束,該行不做處理。Output對于每個給定范圍內(nèi)的取值,如果表達式的值都為素數(shù),則輸出"OK",否則請輸出“Sorry”,每組輸出占一行。Sample Input0 10 0Sample OutputOKAuthorlcySourceC語言程序設(shè)計練習(xí)(二)Statistic | Submit | Back#include <stdio.h>int main() int x, y, sum, i, count, n; while(scanf("%d %d", &x, &y

19、) != EOF && (x!=0 | y!= 0) count = 0; for(n = x; n <= y; +n) sum = n * n + n + 41; for(i = 2; i * i <= sum; +i) if(sum % i = 0) count = 1; if(count = 0) printf("OKn"); else printf("Sorryn"); return 0;2013蟠桃記Time Limit: 2000/1000 MS (Java/Others)   

20、60;Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11490    Accepted Submission(s): 8803Problem Description喜歡西游記的同學(xué)肯定都知道悟空偷吃蟠桃的故事,你們一定都覺得這猴子太鬧騰了,其實你們是有所不知:悟空是在研究一個數(shù)學(xué)問題!什么問題?他研究的問題是蟠桃一共有多少個!不過,到最后,他還是沒能解決這個難題,呵呵-當(dāng)時的情況是這樣的:第一天悟空吃掉桃子總數(shù)一半多一個,第二天又將剩下的桃子吃掉一半多一個,以后每天吃掉前一天剩

21、下的一半多一個,到第n天準(zhǔn)備吃的時候只剩下一個桃子。聰明的你,請幫悟空算一下,他第一天開始吃的時候桃子一共有多少個呢? Input輸入數(shù)據(jù)有多組,每組占一行,包含一個正整數(shù)n(1<n<30),表示只剩下一個桃子的時候是在第n天發(fā)生的。 Output對于每組輸入數(shù)據(jù),輸出第一天開始吃的時候桃子的總數(shù),每個測試實例占一行。 Sample Input24 Sample Output422#include <stdio.h>long pantao (int n) return n = 1 ? 1 : 2 + 2 * pantao(n-1)

22、;int main() int n; while(scanf("%d", &n) != EOF) printf("%dn", pantao(n); return 0;2014青年歌手大獎賽_評委會打分Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17419    Accepted Submission(s):

23、 7801Problem Description青年歌手大獎賽中,評委會給參賽選手打分。選手得分規(guī)則為去掉一個最高分和一個最低分,然后計算平均得分,請編程輸出某選手的得分。 Input輸入數(shù)據(jù)有多組,每組占一行,每行的第一個數(shù)是n(2<n<100),表示評委的人數(shù),然后是n個評委的打分。 Output對于每組輸入數(shù)據(jù),輸出選手的得分,結(jié)果保留2位小數(shù),每組輸出占一行。 Sample Input3 99 98 974 100 99 98 97 Sample Output98.0098.50 Authorlcy SourceC

24、語言程序設(shè)計練習(xí)(三) Recommendlcy#include <stdio.h>int main () int n,i; double sum, averge, max, min, score; while(scanf("%d",&n)!=EOF) scanf("%lf",&score); max = score; min = score; sum = score; for(i=2;i<=n;i+) scanf("%lf",&score); if(score>max) ma

25、x=score; if(score<min) min=score; sum += score; averge=(sum-max-min)/(n-2); printf("%.2fn",averge); return 0;2016數(shù)據(jù)交換輸出Font: Times New Roman | Verdana | GeorgiaFont Size:  Problem Description輸入n(n<100)個數(shù),找出其中最小的數(shù),將它與最前面的數(shù)交換后輸出這些數(shù)。Input輸入數(shù)據(jù)有多組,每組占一行,

26、每行的開始是一個整數(shù)n,表示這個測試實例的數(shù)值的個數(shù),跟著就是n個整數(shù)。n=0表示輸入的結(jié)束,不做處理。Output對于每組輸入數(shù)據(jù),輸出交換后的數(shù)列,每組輸出占一行。Sample Input4 2 1 3 45 5 4 3 2 10Sample Output1 2 3 41 4 3 2 5AuthorlcySourceC語言程序設(shè)計練習(xí)(三)Statistic | Submit | Back#include <stdio.h>int main() int n, i, k, a100,min, temp; while(scanf("

27、%d", &n) != EOF && n != 0) scanf("%d", &a0); min = a0; k = 0; for(i = 1; i < n; +i) scanf("%d", &ai); if(ai < min) min = ai; k = i; temp = a0; a0 = min; ak = temp; for(i = 1; i <= n; +i) if(i !=1) printf(" "); printf("%d", ai-

28、1); printf("n"); return 0;2017字符串統(tǒng)計Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 65   Accepted Submission(s) : 33Font: Times New Roman | Verdana | GeorgiaFont Size:  Pro

29、blem Description對于給定的一個字符串,統(tǒng)計其中數(shù)字字符出現(xiàn)的次數(shù)。Input輸入數(shù)據(jù)有多行,第一行是一個整數(shù)n,表示測試實例的個數(shù),后面跟著n行,每行包括一個由字母和數(shù)字組成的字符串。Output對于每個測試實例,輸出該串中數(shù)值的個數(shù),每個輸出占一行。Sample Input2asdfasdf123123asdfasdfasdf111111111asdfasdfasdfSample Output69AuthorlcySourceC語言程序設(shè)計練習(xí)(三)Statistic | Submit | B#include <stdio.h&g

30、t;int main() int num, n, i; char line; scanf("%d", &n); getchar(); for(i = 1; i <=n; +i) num = 0; for(; (line = getchar() != 'n' ) if(line >='0' && line <= '9') num+; printf("%dn", num); return 0;2024C語言合法標(biāo)識符Time Limit: 2000/1000 MS (J

31、ava/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11613    Accepted Submission(s): 4840Problem Description輸入一個字符串,判斷其是否是C的合法標(biāo)識符。 Input輸入數(shù)據(jù)包含多個測試實例,數(shù)據(jù)的第一行是一個整數(shù)n,表示測試實例的個數(shù),然后是n行輸入數(shù)據(jù),每行是一個長度不超過50的字符串。 Output對于每組輸入數(shù)據(jù),輸出一行。如果輸入數(shù)

32、據(jù)是C的合法標(biāo)識符,則輸出"yes",否則,輸出“no”。 Sample Input312ajffi8x_aff ai_2 Sample Outputnoyesno Authorlcy SourceC語言程序設(shè)計練習(xí)(四) Recommendlcy#include <stdio.h>int main() int n, i, j,frag; char line50; while(scanf("%d", &n) != EOF) getchar(); for(i = 1; i <= n

33、; +i) j = 0; frag = 0; while(linej = getchar() != 'n') if(!(linej='_')|(linej>='0'&&linej<='9')|(linej>='A'&&linej<='Z')|(linej>='a'&&linej<='z') frag = 1; if(line0 >= '0' &&

34、line0 <= '9') frag = 1; +j; if(frag = 0) printf("yes"); else printf("no"); printf("n"); return 0;2025查找最大元素Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10087    

35、;Accepted Submission(s): 5399Problem Description對于輸入的每個字符串,查找其中的最大字母,在該字母后面插入字符串“(max)”。 Input輸入數(shù)據(jù)包括多個測試實例,每個實例由一行長度不超過100的字符串組成,字符串僅由大小寫字母構(gòu)成。 Output對于每個測試實例輸出一行字符串,輸出的結(jié)果是插入字符串“(max)”后的結(jié)果,如果存在多個最大的字母,就在每一個最大字母后面都插入"(max)"。 Sample Inputabcdefgfedcbaxxxxx Sample Outputabc

36、defg(max)fedcbax(max)x(max)x(max)x(max)x(max) Authorlcy SourceC語言程序設(shè)計練習(xí)(四)#include <stdio.h>int main() int i, max, n, j, line100; while(line0=getchar() != EOF) max = line0; i = 1; for(; (linei = getchar() != 'n' +i) if(linei > max) max = linei; n = i; for(j = 0; j <= n;

37、 +j) if(linej = max) printf("%c", linej); printf("(max)"); else printf("%c", linej); /printf("n"); return 0;2081手機短號Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6198  

38、0; Accepted Submission(s): 3955Problem Description Input輸入數(shù)據(jù)的第一行是一個N(N <= 200),表示有N個數(shù)據(jù),接下來的N行每一行為一個11位的手機號碼。 Output輸出應(yīng)包括N行,每行包括一個對應(yīng)的短號,輸出應(yīng)與輸入的順序一致。 Sample Input2 Sample Output645678654321 Source2006/1/15 ACM程序設(shè)計期末考試#include <stdio.h>#include <string.h>int

39、 main () int n, i;char a11;scanf("%d", &n);getchar();while(n-)for(i = 0; i < 6; +i)getchar();gets(a);printf("6%sn", a);return 0;2096小明A+BTime Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10221 &

40、#160;  Accepted Submission(s): 4650Problem Description小明今年3歲了, 現(xiàn)在他已經(jīng)能夠認(rèn)識100以內(nèi)的非負(fù)整數(shù), 并且能夠進行100以內(nèi)的非負(fù)整數(shù)的加法計算.對于大于等于100的整數(shù), 小明僅保留該數(shù)的最后兩位進行計算, 如果計算結(jié)果大于等于100, 那么小明也僅保留計算結(jié)果的最后兩位.例如, 對于小明來說:1) 1234和34是相等的2) 35+80=15給定非負(fù)整數(shù)A和B, 你的任務(wù)是代表小明計算出A+B的值. Input輸入數(shù)據(jù)的第一行為一個正整數(shù)T, 表示測試數(shù)據(jù)的組數(shù). 然后是T組測試數(shù)據(jù). 每組測試

41、數(shù)據(jù)包含兩個非負(fù)整數(shù)A和B(A和B均在int型可表示的范圍內(nèi)). Output對于每組測試數(shù)據(jù), 輸出小明A+B的結(jié)果. Sample Input235 8015 1152 Sample Output1567 SourceHDU 2007-Spring Programming Contest Recommendlcy#include <stdio.h>int main() int T, n, m, i; scanf("%d", &T); for (i = 1; i <= T; +i) scanf(&

42、quot;%d %d", &n, &m); printf("%dn", (n%100 + m%100) % 100); return 0;鹽水的故事#include<stdio.h>void main() int s,t,i;    double vul,d,sum; while(scanf("%lf%lf",&vul,&d)!=EOF)   s=vul/d;  if(vul>s*d) s+;&#

43、160; sum=0;t=0;  for(i=1;i+)     sum+=i*d;   if(sum>=vul)break;      else t+;     s+=t;  printf("%dn",s);   選修課考試作業(yè)1001 Sum Problem21089 A+B for Input-Output Prac

44、tice (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 Input-Output Practice (VII)131096 A+B for Input-Output Practice (VIII)142000

45、 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ā)工資咯:)452033人見人愛A+B462039三角形482040親和數(shù)491001 Sum ProblemProblem DescriptionHey,

46、 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. OutputFor each case, output SUM(n) in one line, followed by a blank line. You may as

47、sume 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) sum=0; for(i=0;i<=n;i+) sum+=i; printf("%dnn",sum); 1089 A+B for I

48、nput-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 one, yes, all these problems were designed for the same aim.  InputThe input

49、 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 one line of output for each line in input.  Sample Input1 510 20 Sampl

50、e 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 DescriptionYour task is to Calculate a + b. InputInput contains an integer N

51、 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 the sum of a and b in one line, and with one line of output for each line in input

52、.  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",&n); for(i=0;i<n;i+) scanf("%d%d",&a,&b); /printf("

53、;%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 test cases. Each test case contains a pair of integers a and b, one pair of integers per

溫馨提示

  • 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論