杭电OJ的输入输出格式题_第1页
杭电OJ的输入输出格式题_第2页
杭电OJ的输入输出格式题_第3页
杭电OJ的输入输出格式题_第4页
杭电OJ的输入输出格式题_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

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

文档简介

1、杭电OJ的输入/输出格式题输入一、1000 A + B Problem题目名称:A + B Problem链接地址:Time Limit: 1 Seconds    Memory Limit:32768KTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Problem DescriptionCalculate A + B.InputEach line will contain two integers A and B.

2、Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2参考答案#include <stdio.h>int main(void) int a,b; while(scanf("%d%d",&a,&b)!=EOF)printf("%dn",a+b);return 0;二、1002 A + B Problem II题目名称:A + B Problem II链接地址:Time Limit: 1 S

3、econds    Memory Limit:32768KTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22627 Accepted Submission(s): 4035Problem DescriptionI have a

4、0;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&#

5、160;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 v

6、ery 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,&#

7、160;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 

8、;= 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 21122334455667788

9、99 998877665544332211Sample OutputCase 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110思路:  本题是手工模拟两个大数相加的问题。两个输入的数字用字符数组存储。不超过1000位,也就是说用整型数定义是不行的,然后想到的就是用整型数组存储和的各位数。具体解题思路如下:  1、先定义两个字符型

10、数组str1和str2,用以保存输入的数字,然后再定义一个整型数组,保存两加数的和的各位。  2、下面来求和计算,先将字符型数组str1中的各位从后面倒着取出,转换成数字存储在整型数组a中(即按相反的顺序进行存放),然后,再将字符型数组str2中的各位从后面倒着取出,转换成数字,然后与a数组中的各位相加,并加入进位,这样相当于将两个数从最低位到最高位进行相加,但是数组a中存放的和是从最低位到最高位,所以输出时要注意。  3、最后就是格式控制好输出。参考答案#include <stdio.h>#include <string.h>#inclu

11、de <stdlib.h>int main() char str11005,str21005; int n,count=0,i,j,flag; int a1005; scanf("%d",&n); while(n-) scanf("%s%s",str1,str2); memset(a,0,sizeof(a); for(i=strlen(str1)-1,j=0;i>=0;i-,j+) aj=str1i-'0' for(i=strlen(str2)-1,j=0;i>=0;i-,j+) aj=aj+str2i-&

12、#39;0' aj+1=aj+1+aj/10; aj=aj%10; count+; printf("Case %d:n",count); printf("%s + %s = ",str1,str2); flag=0; for(i=1004;i>=0;i-) if(flag|ai) printf("%d",ai); flag=1; printf("n"); if(n!=0) printf("n"); return 0;三、1089 A+B for Input-Output Pract

13、ice (I)题目名称:A+B for Input-Output Practice (I)链接地址:Time Limit: 1 Seconds    Memory Limit:32768K1089 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 tha

14、t some problems have the same titles with this 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 s

15、um of a and b in one line, and with one line of output for each line in input. Sample Input1 510 20Sample Output630参考答案#include <stdio.h>int main(void) int a,b; while(scanf("%d%d",&a,&b)!=EOF)printf("%dn",a+b);return 0;四、1090 A+B for Input-Output Practice (II)题目名称:A

16、+B for Input-Output Practice (II)链接地址:Time Limit: 1 Seconds    Memory Limit:32768K输入一开始就会说有n个Input Block,下面接着是输入n个Input Block。参见:HDOJ_1090(1090 A+B for Input-Output Practice (II)Problem DescriptionYour task is to calculate a + b. InputInput contains an integer N in the first line

17、, 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.  Sample input21 5

18、10 20Sample output630参考答案#include <stdio.h>int main() int n,i,a,b; scanf("%d",&n); for(i=0;i<n;i+) scanf("%d %d",&a, &b); printf("%dn",a+b); return 0; 五、1091 A+B for Input-Output Practice (III)题目名称:A+B for Input-Output Practice (III)链接地址:Time Limit:

19、 1 Seconds    Memory Limit:32768K输入不说明有多少个Input Block,但以某个特殊输入为结束标志。参见:HDOJ_1091(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 int

20、egers 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 of output for each line in input.Sample input1 510 200 0Sample output630参考答案#in

21、clude <stdio.h>int main() int a,b;while(scanf("%d %d",&a, &b) !=EOF &&(a!=0 | b!=0) printf("%dn",a+b); return 0;或#include <stdio.h>int main() int a,b;while(scanf("%d %d",&a, &b) !=EOF) if(a=0 && b=0) break; else printf("%

22、dn",a+b); return 0;六、1092 A+B for Input-Output Practice (IV)题目名称:A+B for Input-Output Practice (IV)链接地址:Time Limit: 1 Seconds    Memory Limit:32768K以上几种情况的组合,可以参照如下网页。参见:HDOJ_1092(1092 A+B for Input-Output Practice (IV)Problem DescriptionYour task is to Calculate the sum of

23、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 be processed.OutputFor each group of input integers you should output their sum in on

24、e line, and with one line of output for each line in input.Sample Input4 1 2 3 45 1 2 3 4 50Sample Output1015参考答案#include <stdio.h>int main() int n, sum, i, t; while(scanf("%d", &n) != EOF && n != 0) sum=0; for(i = 0; i < n; i+) scanf("%d", &t); sum = sum

25、 + t; printf("%dn", sum); 七、1093 A+B for Input-Output Practice (V)题目名称:A+B for Input-Output Practice (V)链接地址:Time Limit: 1 Seconds    Memory Limit:32768K以上几种情况的组合,可以参照如下网页。参见:HDOJ_1092(1093 A+B for Input-Output Practice (V)Problem DescriptionYour task is to calculate th

26、e 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. OutputFor each group of input integers you should output their sum in one line, and with one line of output for each lin

27、e in input. Sample Input24 1 2 3 45 1 2 3 4 5Sample Output1015参考答案#include<stdio.h>int main() int n, a, b, i, j, sum; sum = 0; while(scanf("%dn", &n) != EOF) for(i = 0; i < n; i+) scanf("%d", &b); for(j = 0; j < b; j+) scanf("%d", &a); sum += a;

28、printf("%dn", sum); sum = 0; return 0;八、1094 A+B for Input-Output Practice (VI)题目名称:A+B for Input-Output Practice (VI)链接地址:Time Limit: 1 Seconds    Memory Limit:32768K以上几种情况的组合,可以参照如下网页。参见:HDOJ_1092(1094 A+B for Input-Output Practice (VI)Problem DescriptionYour task is

29、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 of N integers in one line, and with one line of output for each li

30、ne in input. Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015参考答案#include<stdio.h>int main() int n, a, b, i, j, sum; sum=0; while(scanf("%dn",&n)!=EOF ) for(j=0;j<n;j+) scanf("%d",&a); sum+=a; printf("%dn",sum); sum=0; return 0;输出1、第一类输出一个Input Block对应

31、一个Output Block,Output Block之间没有空行。参见:HDOJ_1089(2、第二类输出一个Input Block对应一个Output Block,每个Output Block之后都有空行。参见:HDOJ_1095(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,

32、 one pair of integers per line. OutputFor 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 20Sample Output630参考答案#include <stdio.h>int main() int a,b; while(scanf("%d %d",&a, &b) != EOF) printf("%dn

33、n",a+b); 3、第三类输出一个Input Block对应一个Output Block,Output Block之间有空行。参见:HDOJ_1096(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 intege

34、r 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 you must note that there is a blank line between outputs.Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3Sample Output10156参考答案#include <stdio.h>int main() int icase,n,

35、i,j,a,sum; scanf("%d",&icase); for(i=0;i<icase;i+) sum=0; scanf("%d",&n); for(j=0;j<n;j+) scanf("%d",&a); sum+=a; if(i<icase-1) printf("%dnn",sum); else printf("%dn",sum); 1229 还是A+B参见:HDOJ_1229(Time Limit: 2000/1000 MS (Java/Oth

36、ers) Memory Limit: 65536/32768 K (Java/Others),Total Submission(s): 15959 Accepted Submission(s): 7765Problem Description读入两个小于10000的正整数A和B,计算A+B。需要注意的是:如果A和B的末尾K(不超过8)位数字相同,请直接输出-1。Input测试输入包含若干测试用例,每个测试用例占一行,格式为"A B K",相邻两数字有一个空格间隔。当A和B同时为0时输入结束,相应的结果不要输出。Output对每个测试用例输出1行,即A+B的值或者是-1。Sa

37、mple Input1 2 111 21 1108 8 236 64 30 0 1Sample Output3-1-1100参考答案#include <stdio.h>#include <math.h>int main() int a,b,n,i,sum; while(scanf("%d%d%d",&a,&b,&n)=3) if(a=0 && b=0) break; sum=(int)pow(10,n); if(a%sum = b%sum) printf("-1n"); else print

38、f("%dn",a+b); return 0; 说明:上面的sum=(int)pow(10,n);实际上是求10有n次方,也可以用下面的循环来求得:sum=1; for(i=1;i<=n;i+) sum*=10; 1106 排序参见:HDOJ_1106(Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others),Total Submission(s): 15959 Accepted Submission(s): 7765Problem Description输入一行数

39、字,如果我们把这行数字中的5都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以0开头,这些头部的0应该被忽略掉,除非这个整数就是由若干个0组成的,这时这个整数就是0)。你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。Input输入包含多组测试用例,每组输入数据只有一行数字(数字之间没有空格),这行数字的长度不大于1000。  输入数据保证:分割得到的非负整数不会大于100000000;输入数据不可能全由5组成。Output对于每个测试用例,输出分割得到的整数排序的结果,相邻的两个整数之间用一个空格分开,每组输出占一行。Sample Input00

40、51231232050775Sample Output0 77 12312320参考答案#include <cstdio> /cstdio就是将stdio.h的内容用C+的头文件形式表现出来#include <cstring>#include <algorithm> /需要用到C+中对数组进行升幂排序sort,需要包含头文件<algorithm>using namespace std;int main() char str1100; int i,k,len,sum,ws; /ws存储子字符串位数,k存储已得到的整数个数 int a1100; /把

41、分割后的数值存入数组a中 while(scanf("%s",str)!=EOF) len=strlen(str); sum=0; ws=0; k=0; /ws存储子字符串位数,k存储已得到的整数个数 for(i=0;i<=len; i+) if(stri='5' | stri='0') /意味着一个数结束,把数存入到ak if(ws>0) ak+=sum; ws=0; sum=0; /为计算下一个数做准备 else /stri!=5且stri!='0',即stri为有效数字 sum=sum*10+stri-'

42、;0' ws+; sort(a,a+k); /调用C+中的sort排序方法 printf("%d",a0); /a0需要分开打印,因为它前面无空格 for(i=1;i<k;i+) printf(" %d",ai); printf("n"); return 0;1003 Max Sum参见:HDOJ_1003(Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 53856 A

43、ccepted Submission(s): 12109Problem DescriptionGiven a sequence a1,a2,a3.an, your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<=T<=20) which me

44、ans the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test

45、case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.Sample Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5 Sample

46、 Output Case 1:14 1 4Case 2:7 1 6 参考程序:#include <stdio.h>int main() /t为输入测试样例的组数,n为每个测试样例的数据元素的个数 /begin用来暂时存储b保留的和的起始位置,step为测试样例的个数 int n,t,b,begin,step=1,i,now; /maxsum保留之前算出来的最大和,b存储目前在读入数据前保留的和,now为每次输入数据int besti, bestj,maxsum;scanf("%d",&t);while (t-) scanf("%d",

47、&n); for ( i=1; i<=n; i+) scanf("%d", &now); if(i=1) /初始化 maxsum=b=now; /maxsum保留之前算出来的最大和,b存储目前在读入数据前保留的和,ai为读入数据 begin=besti=bestj=1;/begin用来暂时存储b保留的和的起始位置,当b>maxsum时将begin赋在besti位置,besti,bestj保留最大和的开始和结束位置 else if (now>b+now) /如果之前存储的和b加上现在的数据now比现在的数据小,就把存储的和换成现在的数据, b=now; begin = i; /预存的位置要重置 else b+=now; /反之就说明数据在递增,可以直接加上 if (b>maxsum) /跟之前算出来的最大和进行比较,如果大于,位置和数据就要重置 maxsum = b; besti = begin; bestj = i; printf("Case %d:n%d

温馨提示

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

评论

0/150

提交评论