杭电OJ的输入输出格式题课案

上传人:我** 文档编号:114631151 上传时间:2019-11-12 格式:DOC 页数:18 大小:147KB
返回 下载 相关 举报
杭电OJ的输入输出格式题课案_第1页
第1页 / 共18页
杭电OJ的输入输出格式题课案_第2页
第2页 / 共18页
杭电OJ的输入输出格式题课案_第3页
第3页 / 共18页
杭电OJ的输入输出格式题课案_第4页
第4页 / 共18页
杭电OJ的输入输出格式题课案_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《杭电OJ的输入输出格式题课案》由会员分享,可在线阅读,更多相关《杭电OJ的输入输出格式题课案(18页珍藏版)》请在金锄头文库上搜索。

1、杭电OJ的输入/输出格式题输入一、1000 A + B Problem题目名称:A + B Problem链接地址:http:/ Limit: 1 SecondsMemory 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. Process to end of file.OutputFor ea

2、ch case, output A + B in one line.Sample Input1 1Sample Output2参考答案#include 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链接地址:http:/ Limit: 1 SecondsMemory Limit:32768KTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/327

3、68K(Java/Others)TotalSubmission(s):22627AcceptedSubmission(s):4035ProblemDescriptionIhaveaverysimpleproblemforyou.GiventwointegersAandB,yourjobistocalculatetheSumofA+B.InputThefirstlineoftheinputcontainsanintegerT(1=T=20)whichmeansthenumberoftestcases.ThenTlinesfollow,eachlineconsistsoftwopositivein

4、tegers,AandB.Noticethattheintegersareverylarge,thatmeansyoushouldnotprocessthembyusing32-bitinteger.Youmayassumethelengthofeachintegerwillnotexceed1000.OutputForeachtestcase,youshouldoutputtwolines.ThefirstlineisCase#:,#meansthenumberofthetestcase.ThesecondlineistheanequationA+B=Sum,Summeanstheresul

5、tofA+B.Notetherearesomespacesinttheequation.Outputablanklinebetweentwotestcases.SampleInput212112233445566778899998877665544332211SampleOutputCase1:1+2=3Case2:112233445566778899+998877665544332211=1111111111111111110思路:本题是手工模拟两个大数相加的问题。两个输入的数字用字符数组存储。不超过1000位,也就是说用整型数定义是不行的,然后想到的就是用整型数组存储和的各位数。具体解题思

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

7、5; 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-0; aj+1=aj+1+aj/10; aj=aj%10; count+; printf(Case %d:n,count); printf(%s + %s = ,str1,str2); flag

8、=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 Practice (I)题目名称:A+B for Input-Output Practice (I)链接地址:http:/ Limit: 1 SecondsMemory Limit:32768K1089 A+B for Input-Output Practice (I)Problem DescriptionYour task is to Calc

9、ulate 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 will consist of a series of pairs of integers a and b, separated by

10、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 20Sample Output630参考答案#include int main(void) int a,b; while(scanf(%d%d,&a,&b)!=EOF)printf(%dn

11、,a+b);return 0;四、1090 A+B for Input-Output Practice (II)题目名称:A+B for Input-Output Practice (II)链接地址:http:/ Limit: 1 SecondsMemory Limit:32768K输入一开始就会说有n个Input Block,下面接着是输入n个Input Block。参见:HDOJ_1090(http:/ A+B for Input-Output Practice (II)Problem DescriptionYour task is to calculate a + b. InputInp

12、ut contains an integer N 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. Sample input21 510 20Sample output630参考答案#include int main() int n,i,a,b; scanf(%d,&n); for(i=0;in;i+) scanf(%d %d,&a, &b); printf(%dn,a+b); return 0; 五、1091 A+B f

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号