杭电ACM水题题目及代码_第1页
杭电ACM水题题目及代码_第2页
杭电ACM水题题目及代码_第3页
杭电ACM水题题目及代码_第4页
杭电ACM水题题目及代码_第5页
已阅读5页,还剩70页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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;成绩转换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,将其转换成对应的等级,具体转换规则如下:90100为A;8089为B;7079为C;6069为D;059为E; Input输入数据有多组,每组占一行,由一个整数组成。 Output对于每组输入数据,输出一行。如果输入数据不在0100范围内,请输出一行:“Score is error!”。 Sample Input5667100123 Sample OutputEDAScore is error! Authorlcy SourceC语言程序设计练习(一) 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给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。Input输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。Output对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。你可以认为32位整数足以保存结果。Sample Input1 32 5Sample Output4 28

12、20 152AuthorlcySourceC语言程序设计练习(一)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水仙花数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春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+33。现在要求输出所有在m和n范围内的水仙花数。Input输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。Output对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;如果给定的范围内

15、不存在水仙花数,则输出no;每个测试实例的输出占一行。Sample Input100 120300 380Sample Outputno370 371AuthorlcySourceC语言程序设计练习(二)#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 素数判定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,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。Input输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=

18、0时,表示输入结束,该行不做处理。Output对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。Sample Input0 10 0Sample OutputOKAuthorlcySourceC语言程序设计练习(二)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喜欢西游记的同学肯定都知道悟空偷吃蟠桃的故事,你们一定都觉得这猴子太闹腾了,其实你们是有所不知:悟空是在研究一个数学问题!什么问题?他研究的问题是蟠桃一共有多少个!不过,到最后,他还是没能解决这个难题,呵呵-当时的情况是这样的:第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩

21、下的一半多一个,到第n天准备吃的时候只剩下一个桃子。聪明的你,请帮悟空算一下,他第一天开始吃的时候桃子一共有多少个呢? Input输入数据有多组,每组占一行,包含一个正整数n(1<n<30),表示只剩下一个桃子的时候是在第n天发生的。 Output对于每组输入数据,输出第一天开始吃的时候桃子的总数,每个测试实例占一行。 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青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分。 Input输入数据有多组,每组占一行,每行的第一个数是n(2<n<100),表示评委的人数,然后是n个评委的打分。 Output对于每组输入数据,输出选手的得分,结果保留2位小数,每组输出占一行。 Sample Input3 99 98 974 100 99 98 97 Sample Output98.0098.50 Authorlcy SourceC

24、语言程序设计练习(三) 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数据交换输出Font: Times New Roman | Verdana | GeorgiaFont Size:  Problem Description输入n(n<100)个数,找出其中最小的数,将它与最前面的数交换后输出这些数。Input输入数据有多组,每组占一行,

26、每行的开始是一个整数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 <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字符串统计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对于给定的一个字符串,统计其中数字字符出现的次数。Input输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。Output对于每个测试实例,输出该串中数值的个数,每个输出占一行。Sample Input2asdfasdf123123asdfasdfasdf111111111asdfasdfasdfSample Output69AuthorlcySourceC语言程序设计练习(三)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语言合法标识符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的合法标识符。 Input输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。 Output对于每组输入数据,输出一行。如果输入数

32、据是C的合法标识符,则输出"yes",否则,输出“no”。 Sample Input312ajffi8x_aff ai_2 Sample Outputnoyesno Authorlcy SourceC语言程序设计练习(四) 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输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。 Output对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入"(max)"。 Sample Inputabcdefgfedcbaxxxxx Sample Outputabc

36、defg(max)fedcbax(max)x(max)x(max)x(max)x(max) Authorlcy SourceC语言程序设计练习(四)#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输入数据的第一行是一个N(N <= 200),表示有N个数据,接下来的N行每一行为一个11位的手机号码。 Output输出应包括N行,每行包括一个对应的短号,输出应与输入的顺序一致。 Sample Input2 Sample Output645678654321 Source2006/1/15 ACM程序设计期末考试#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岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算.对于大于等于100的整数, 小明仅保留该数的最后两位进行计算, 如果计算结果大于等于100, 那么小明也仅保留计算结果的最后两位.例如, 对于小明来说:1) 1234和34是相等的2) 35+80=15给定非负整数A和B, 你的任务是代表小明计算出A+B的值. Input输入数据的第一行为一个正整数T, 表示测试数据的组数. 然后是T组测试数据. 每组测试

41、数据包含两个非负整数A和B(A和B均在int型可表示的范围内). Output对于每组测试数据, 输出小明A+B的结果. 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);   选修课考试作业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成绩转换212005第几天?222006求奇数的乘积242007平方和与立方和262008数值统计272009求数列的和282010水仙花数292011多项式求和312012素数判定332014青年歌手大奖赛_评委会打分342015偶数求和362016数据的交换输出382017字符串统计402019数列有序!412020绝对值排序432021发工资咯:)452033人见人爱A+B462039三角形482040亲和数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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论