ACM部分练习题目答案.doc_第1页
ACM部分练习题目答案.doc_第2页
ACM部分练习题目答案.doc_第3页
ACM部分练习题目答案.doc_第4页
ACM部分练习题目答案.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

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

文档简介

ACM部分习题答案:A + B ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 100972 Accepted Submission(s): 33404Problem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2# includeInt main()int x,y,s; while(scanf(%d %d,&x,&y)!=EOF) s=x+y; printf(%dn,s); return 0;Sum ProblemTime Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 85964 Accepted Submission(s): 19422Problem 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 Output15050# includeint main()int n; long int s; while(scanf(%d,&n)!=EOF) s=0; while(n0) s=s+n; n-; printf(%ldnn,s); return 0;A + B Problem IITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58216 Accepted Submission(s): 10500Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is 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 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 result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110#include #include int main() char x1001,y1001,z1001; int n,i,j,k,m,o; scanf(%d,&n); o=n; while(n-) scanf(%s%s,x,y); i=strlen(x); j=strlen(y); for(k=0,m=0;i0&j0;i-,j-) m+=xi-1-0+yj-1-0; zk+=m%10+0; m/=10; for(;i0;i-) m+=xi-1-0; zk+=m%10+0; m/=10; for(;j0;j-) m+=yj-1-0; zk+=m%10+0; m/=10; if(m0) zk+=m%10+0; printf(Case %d:n%s + %s = ,o-n,x,y); for(;k0;k-) printf(%c,zk-1); printf(n); if(n) printf(n); return 0;Let the Balloon RiseTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24082 Accepted Submission(s): 7343Problem DescriptionContest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.This year, they decide to leave this lovely job to you. InputInput contains multiple test cases. Each test case starts with a number N (0 N = 1000) - the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.A test case with N = 0 terminates the input and this test case is not to be processed.OutputFor each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.Sample Input5greenredblueredred3pinkorangepink0Sample Outputredpink#include#includevoid main() int n,i,j,k,t,a1001; char h100116; while(scanf(%d,&n)!=EOF) if(n=0) break; for(i=0;i=n;+i) ai=0; t=i=k=0; while(in) scanf(%s,hi+); for(i=0;in;+i) for(j=i+1;jk) k=ai; t=i; printf(%sn,ht); ElevatorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12849 Accepted Submission(s): 6646Problem DescriptionThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.InputThere are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.OutputPrint the total time on a single line for each test case. Sample Input1 23 2 3 10Sample Output1741#include int main() int a,b,n,t; while(scanf(%d,&n)!=EOF&n) t=0;b=0; t+=n*5;/停的总时间累加起来 while(n-) scanf(%d,&a); if(ab)t+=6*(a-b);/与前次比若上升 else if(ab)t+=4*(b-a);/与前次比若下降 b=a; printf(%dn,t); return 0;Digital RootsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16322 Accepted Submission(s): 4610Problem DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.InputThe input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.OutputFor each integer in the input, output its digital root on a separate line of the output.Sample Input24390Sample Output63#include#includeint main() int l,s,i; char a1000; while(scanf(%s,a) l=strlen(a); s=0; if(l=1&(strcmp(a,0)=0) ) break; else for(i=0;i9) l=0; while (s) l+=s%10; s/=10; s=l; s=(s%10+s/10); printf(%dn,s); return 0;As Easy As A+BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12198 Accepted Submission(s): 4870Problem DescriptionThese days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.Give you some integers, your task is to sort these number ascending (升序).You should know how ea

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论