《杭电ACM水题题目及代码.docx》由会员分享,可在线阅读,更多相关《杭电ACM水题题目及代码.docx(50页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精品文档,仅供学习与交流,如有侵权请联系网站删除1002 A + B Problem IITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 69615Accepted Submission(s): 12678Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of
2、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 by using 32-bit integer. You may assum
3、e 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 result of A + B. Note there are some spaces int the equation. Output
4、a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110AuthorIgnatius.L#include #include int main()char str11001, str21001;int t, i, len_str1, len_str2, len_max, num = 1
5、, 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 len_str2)len_max = len_str1;elselen_max = len_str2;k = 0;for(i = 0; i = 0
6、; -i)printf(%d, ci);printf(n);if(t = 1)printf(n);return 0;成绩转换Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25250 Accepted Submission(s): 10776Problem Description输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:90100为A;8089为B;7079为C;6069为D;059为E;Input输入数据有多组,每组占
7、一行,由一个整数组成。Output对于每组输入数据,输出一行。如果输入数据不在0100范围内,请输出一行:“Score is error!”。Sample Input5667100123Sample OutputEDAScore is error!AuthorlcySourceC语言程序设计练习(一)RecommendJGShining#include int main() int n, k; while(scanf(%d, &n) != EOF) if(n 100) printf(Score is error!n); else k = n / 10; switch(k) case 10: p
8、rintf(An); break; case 9: printf(An); break; case 8: printf(Bn); break; 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) : 65Accepted Submission(s) :
9、9Font:Times New Roman|Verdana|GeorgiaFont Size:Problem Description给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。Input输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。Output对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。你可以认为32位整数足以保存结果。Sample Input1 32 5Sample Output4 2820 152AuthorlcySourceC语言程序设计练习(一)Statistic|#in
10、clude 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 * x * x; printf(%d %dn, sum1, sum2); return 0;2010水仙花数Time Limit : 2000/1000ms (Java/Other)Memory Limi
11、t : 65536/32768K (Java/Other)Total Submission(s) : 144Accepted Submission(s) : 27Font:Times New Roman|Verdana|GeorgiaFont Size:Problem Description春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+33。现在要求输出所有在m和n范围内的水仙花数。Input输入数据有多组,每组占一行,包括两个整数m和n(100=m=n=999)。Outp
12、ut对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;如果给定的范围内不存在水仙花数,则输出no;每个测试实例的输出占一行。Sample Input100 120300 380Sample Outputno370 371AuthorlcySourceC语言程序设计练习(二)#include int main() int m, n, k1, k2, k3, count; while(scanf(%d %d, &m, &n) != EOF) for(count = 0; m =
13、 n; +m) k1 = m / 100; k2 = (m - 100 * k1) / 10; k3 = (m -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 素数判定Time Limit : 2000/1000ms (Java/Other)Memory Limit : 65536/32768K (Java/Oth
14、er)Total Submission(s) : 29Accepted Submission(s) : 15Font:Times New Roman|Verdana|GeorgiaFont Size:Problem Description对于表达式n2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39=xy=50),判定该表达式的值是否都为素数。Input输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。Output对于每个给定范围内的取值,如果表达式的值都为素数,则输出OK,否则请输出“Sorry”,每组输出占一行。Sample
15、 Input0 10 0Sample OutputOKAuthorlcySourceC语言程序设计练习(二)Statistic|Submit|Back#include int main() int x, y, sum, i, count, n; while(scanf(%d %d, &x, &y) != 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) pr
16、intf(OKn); else printf(Sorryn); return 0;2013蟠桃记Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11490Accepted Submission(s): 8803Problem Description喜欢西游记的同学肯定都知道悟空偷吃蟠桃的故事,你们一定都觉得这猴子太闹腾了,其实你们是有所不知:悟空是在研究一个数学问题!什么问题?他研究的问题是蟠桃一共有多少个!不过,到最后,他还是没能解决这个难题
17、,呵呵-当时的情况是这样的:第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩下的一半多一个,到第n天准备吃的时候只剩下一个桃子。聪明的你,请帮悟空算一下,他第一天开始吃的时候桃子一共有多少个呢?Input输入数据有多组,每组占一行,包含一个正整数n(1n30),表示只剩下一个桃子的时候是在第n天发生的。Output对于每组输入数据,输出第一天开始吃的时候桃子的总数,每个测试实例占一行。Sample Input24Sample Output422#include long pantao (int n) return n = 1 ? 1 : 2 + 2 *
18、 pantao(n-1);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): 17419Accepted Submission(s): 7801Problem Description青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分
19、,然后计算平均得分,请编程输出某选手的得分。Input输入数据有多组,每组占一行,每行的第一个数是n(2n100),表示评委的人数,然后是n个评委的打分。Output对于每组输入数据,输出选手的得分,结果保留2位小数,每组输出占一行。Sample Input3 99 98 974 100 99 98 97Sample Output98.0098.50AuthorlcySourceC语言程序设计练习(三)Recommendlcy#include int main () int n,i; double sum, averge, max, min, score; while(scanf(%d,&n)
20、!=EOF) scanf(%lf,&score); max = score; min = score; sum = score; for(i=2;imax) max=score; if(scoremin) min=score; sum += score; averge=(sum-max-min)/(n-2); printf(%.2fn,averge); return 0;2016数据交换输出Font:Times New Roman|Verdana|GeorgiaFont Size:Problem Description输入n(n100)个数,找出其中最小的数,将它与最前面的数交换后输出这些数。
21、Input输入数据有多组,每组占一行,每行的开始是一个整数n,表示这个测试实例的数值的个数,跟着就是n个整数。n=0表示输入的结束,不做处理。Output对于每组输入数据,输出交换后的数列,每组输出占一行。Sample Input4 2 1 3 45 5 4 3 2 10Sample Output1 2 3 41 4 3 2 5AuthorlcySourceC语言程序设计练习(三)Statistic|Submit|Back#include int main() int n, i, k, a100,min, temp; while(scanf(%d, &n) != EOF & n != 0) s
22、canf(%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-1); printf(n); return 0;2017字符串统计Time Limit : 2000/1000ms (Java/Other)Memory Limit : 65536/32768K (Java/Other)Total
23、 Submission(s) : 65Accepted Submission(s) : 33Font:Times New Roman|Verdana|GeorgiaFont Size:Problem Description对于给定的一个字符串,统计其中数字字符出现的次数。Input输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。Output对于每个测试实例,输出该串中数值的个数,每个输出占一行。Sample Input2asdfasdf123123asdfasdfasdf111111111asdfasdfasdfSample Outp
24、ut69AuthorlcySourceC语言程序设计练习(三)Statistic|Submit|B#include int main() int num, n, i; char line; scanf(%d, &n); getchar(); for(i = 1; i =0 & line = 9) num+; printf(%dn, num); return 0;2024C语言合法标识符Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11613A
25、ccepted Submission(s): 4840Problem Description输入一个字符串,判断其是否是C的合法标识符。Input输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。Output对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出yes,否则,输出“no”。Sample Input312ajffi8x_aff ai_2Sample OutputnoyesnoAuthorlcySourceC语言程序设计练习(四)Recommendlcy#include int main() in
26、t n, i, j,frag; char line50; while(scanf(%d, &n) != EOF) getchar(); for(i = 1; i =0&linej=A&linej=a&linej= 0 & 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 Submis
27、sion(s): 10087Accepted Submission(s): 5399Problem Description对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。Input输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。Output对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入(max)。Sample InputabcdefgfedcbaxxxxxSample Outputabcdefg(max)fedcbax(max)x(
28、max)x(max)x(max)x(max)AuthorlcySourceC语言程序设计练习(四)#include 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; +j) if(linej = max) printf(%c, linej); printf(max); else printf(%c,
29、 linej); /printf(n); return 0;2081手机短号Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6198Accepted Submission(s): 3955Problem Description大家都知道,手机号是一个11位长的数字串,同时,作为学生,还可以申请加入校园网,如果加入成功,你将另外拥有一个短号。假设所有的短号都是是 6+手机号的后5位,比如号码为13512345678的手机,对应的短号就是64567
30、8。现在,如果给你一个11位长的手机号码,你能找出对应的短号吗?Input输入数据的第一行是一个N(N = 200),表示有N个数据,接下来的N行每一行为一个11位的手机号码。Output输出应包括N行,每行包括一个对应的短号,输出应与输入的顺序一致。Sample Input21351234567813787654321Sample Output645678654321Source2006/1/15 ACM程序设计期末考试#include #include int main () int n, i;char a11;scanf(%d, &n);getchar();while(n-)for(i
31、= 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): 10221Accepted Submission(s): 4650Problem Description小明今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算.对于大于等于100的整数, 小明仅保留该数的最后两位进行计算,
32、 如果计算结果大于等于100, 那么小明也仅保留计算结果的最后两位.例如, 对于小明来说:1) 1234和34是相等的2) 35+80=15给定非负整数A和B, 你的任务是代表小明计算出A+B的值.Input输入数据的第一行为一个正整数T, 表示测试数据的组数. 然后是T组测试数据. 每组测试数据包含两个非负整数A和B(A和B均在int型可表示的范围内).Output对于每组测试数据, 输出小明A+B的结果.Sample Input235 8015 1152Sample Output1567SourceHDU 2007-Spring Programming ContestRecommendlc
33、y#include int main() int T, n, m, i; scanf(%d, &T); for (i = 1; i = T; +i) scanf(%d %d, &n, &m); printf(%dn, (n%100 + m%100) % 100); return 0;盐水的故事#includevoid main()int s,t,i; double vul,d,sum;while(scanf(%lf%lf,&vul,&d)!=EOF)s=vul/d;if(vuls*d) s+;sum=0;t=0;for(i=1;i+)sum+=i*d;if(sum=vul)break; els
34、e t+;s+=t;printf(%dn,s); 选修课考试作业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 f
35、or Input-Output Practice (VII)131096 A+B for Input-Output Practice (VIII)142000 ASCII码排序162001计算两点间的距离172002计算球体积192003求绝对值202004成绩转换212005第几天?222006求奇数的乘积242007平方和与立方和262008数值统计272009求数列的和282010水仙花数292011多项式求和312012素数判定332014青年歌手大奖赛_评委会打分342015偶数求和362016数据的交换输出382017字符串统计402019数列有序!412020绝对值排序43202
36、1发工资咯:)452033人见人爱A+B462039三角形482040亲和数49【精品文档】第 50 页1001 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.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()