杭电OJ的输入输出格式题.docx

上传人:b****1 文档编号:3255630 上传时间:2023-05-05 格式:DOCX 页数:28 大小:22.11KB
下载 相关 举报
杭电OJ的输入输出格式题.docx_第1页
第1页 / 共28页
杭电OJ的输入输出格式题.docx_第2页
第2页 / 共28页
杭电OJ的输入输出格式题.docx_第3页
第3页 / 共28页
杭电OJ的输入输出格式题.docx_第4页
第4页 / 共28页
杭电OJ的输入输出格式题.docx_第5页
第5页 / 共28页
杭电OJ的输入输出格式题.docx_第6页
第6页 / 共28页
杭电OJ的输入输出格式题.docx_第7页
第7页 / 共28页
杭电OJ的输入输出格式题.docx_第8页
第8页 / 共28页
杭电OJ的输入输出格式题.docx_第9页
第9页 / 共28页
杭电OJ的输入输出格式题.docx_第10页
第10页 / 共28页
杭电OJ的输入输出格式题.docx_第11页
第11页 / 共28页
杭电OJ的输入输出格式题.docx_第12页
第12页 / 共28页
杭电OJ的输入输出格式题.docx_第13页
第13页 / 共28页
杭电OJ的输入输出格式题.docx_第14页
第14页 / 共28页
杭电OJ的输入输出格式题.docx_第15页
第15页 / 共28页
杭电OJ的输入输出格式题.docx_第16页
第16页 / 共28页
杭电OJ的输入输出格式题.docx_第17页
第17页 / 共28页
杭电OJ的输入输出格式题.docx_第18页
第18页 / 共28页
杭电OJ的输入输出格式题.docx_第19页
第19页 / 共28页
杭电OJ的输入输出格式题.docx_第20页
第20页 / 共28页
亲,该文档总共28页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

杭电OJ的输入输出格式题.docx

《杭电OJ的输入输出格式题.docx》由会员分享,可在线阅读,更多相关《杭电OJ的输入输出格式题.docx(28页珍藏版)》请在冰点文库上搜索。

杭电OJ的输入输出格式题.docx

杭电OJ的输入输出格式题

杭电OJ的输入/输出格式题

输入

一、1000A+BProblem

题目名称:

A+BProblem

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

TimeLimit:

2000/1000MS(Java/Others)  MemoryLimit:

65536/32768K(Java/Others)

ProblemDescription

CalculateA+B.

Input

EachlinewillcontaintwointegersAandB.Processtoendoffile.

Output

Foreachcase,outputA+Binoneline.

SampleInput

11

SampleOutput

2

参考答案

#include

intmain(void)

{

inta,b;

while(scanf("%d%d",&a,&b)!

=EOF)

printf("%d\n",a+b);

return0;

}

 

二、1002A+BProblemII

题目名称:

A+BProblemII

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

Time Limit:

 2000/1000 MS (Java/Others) Memory Limit:

 65536/32768 K (Java/Others)

Total Submission(s):

 22627 Accepted Submission(s):

 4035

Problem Description

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input

The 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.

Output

For 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 Input

2

1 2

112233445566778899 998877665544332211

Sample Output

Case 1:

1 + 2 = 3

Case 2:

112233445566778899 + 998877665544332211 = 111111*********1110

思路:

  本题是手工模拟两个大数相加的问题。

两个输入的数字用字符数组存储。

不超过1000位,也就是说用整型数定义是不行的,然后想到的就是用整型数组存储和的各位数。

具体解题思路如下:

  1、先定义两个字符型数组str1和str2,用以保存输入的数字,然后再定义一个整型数组,保存两加数的和的各位。

  2、下面来求和计算,先将字符型数组str1中的各位从后面倒着取出,转换成数字存储在整型数组a中(即按相反的顺序进行存放),然后,再将字符型数组str2中的各位从后面倒着取出,转换成数字,然后与a数组中的各位相加,并加入进位,这样相当于将两个数从最低位到最高位进行相加,但是数组a中存放的和是从最低位到最高位,所以输出时要注意。

 3、最后就是格式控制好输出。

参考答案

#include

#include

#include

intmain()

{

charstr1[1005],str2[1005];

intn,count=0,i,j,flag;

inta[1005];

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++)

a[j]=str1[i]-'0';

for(i=strlen(str2)-1,j=0;i>=0;i--,j++)

{

a[j]=a[j]+str2[i]-'0';

a[j+1]=a[j+1]+a[j]/10;

a[j]=a[j]%10;

}

count++;

printf("Case%d:

\n",count);

printf("%s+%s=",str1,str2);

flag=0;

for(i=1004;i>=0;i--)

if(flag||a[i])

{

printf("%d",a[i]);

flag=1;

}

printf("\n");

if(n!

=0)printf("\n");

}

return0;

}

 

三、1089A+BforInput-OutputPractice(I)

题目名称:

A+BforInput-OutputPractice(I)

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

1089A+BforInput-OutputPractice(I)

ProblemDescription

YourtaskistoCalculatea+b.

Tooeasy?

!

Ofcourse!

Ispeciallydesignedtheproblemforacmbeginners.

Youmusthavefoundthatsomeproblemshavethesametitleswiththisone,yes,alltheseproblemsweredesignedforthesameaim.

Input

Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.

Output

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.

SampleInput

15

1020

SampleOutput

6

30

参考答案

#include

intmain(void)

{

inta,b;

while(scanf("%d%d",&a,&b)!

=EOF)

printf("%d\n",a+b);

return0;

}

四、1090A+BforInput-OutputPractice(II)

题目名称:

A+BforInput-OutputPractice(II)

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

输入一开始就会说有n个InputBlock,下面接着是输入n个InputBlock。

参见:

HDOJ_1090(

1090A+BforInput-OutputPractice(II)

ProblemDescription

Yourtaskistocalculatea+b.

Input

InputcontainsanintegerNinthefirstline,andthenNlinesfollow.Eachlineconsistsofapairofintegersaandb,separatedbyaspace,onepairofintegersperline.

Output

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput. 

Sampleinput

2

15

1020

Sampleoutput

6

30

参考答案

#include

intmain()

{

intn,i,a,b;

scanf("%d",&n);

for(i=0;i

{

scanf("%d%d",&a,&b);

printf("%d\n",a+b);

}

return0;

}

 

五、1091A+BforInput-OutputPractice(III)

题目名称:

A+BforInput-OutputPractice(III)

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

输入不说明有多少个InputBlock,但以某个特殊输入为结束标志。

参见:

HDOJ_1091(

1091A+BforInput-OutputPractice(III)

ProblemDescription

Yourtaskistocalculatea+b.

Input

Inputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.

Output

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.

Sampleinput

15

1020

00

Sampleoutput

6

30

参考答案

#include

intmain()

{

inta,b;

while(scanf("%d%d",&a,&b)!

=EOF&&(a!

=0||b!

=0))

printf("%d\n",a+b);

return0;

}

#include

intmain()

{

inta,b;

while(scanf("%d%d",&a,&b)!

=EOF)

if(a==0&&b==0)

break;

else

printf("%d\n",a+b);

return0;

}

 

六、1092A+BforInput-OutputPractice(IV)

题目名称:

A+BforInput-OutputPractice(IV)

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

以上几种情况的组合,可以参照如下网页。

参见:

HDOJ_1092(

1092A+BforInput-OutputPractice(IV)

ProblemDescription

YourtaskistoCalculatethesumofsomeintegers.

Input

Inputcontainsmultipletestcases.EachtestcasecontainsaintegerN,andthenNintegersfollowinthesameline.Atestcasestartingwith0terminatestheinputandthistestcaseisnottobeprocessed.

Output

Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.

SampleInput

41234

512345

0

SampleOutput

10

15

参考答案

#include

intmain()

{

intn,sum,i,t;

while(scanf("%d",&n)!

=EOF&&n!

=0)

{

sum=0;

for(i=0;i

{

scanf("%d",&t);

sum=sum+t;

}

printf("%d\n",sum);

}

}

 

七、1093A+BforInput-OutputPractice(V)

题目名称:

A+BforInput-OutputPractice(V)

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

以上几种情况的组合,可以参照如下网页。

参见:

HDOJ_1092(

1093A+BforInput-OutputPractice(V)

ProblemDescription

Yourtaskistocalculatethesumofsomeintegers.

Input

InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.

Output

Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.

SampleInput

2

41234

512345

SampleOutput

10

15

参考答案

#include

intmain()

{

intn,a,b,i,j,sum;

sum=0;

while(scanf("%d\n",&n)!

=EOF)

{

for(i=0;i

{

scanf("%d",&b);

for(j=0;j

{

scanf("%d",&a);

sum+=a;

}

printf("%d\n",sum);

sum=0;

}

}

return0;

}

八、1094A+BforInput-OutputPractice(VI)

题目名称:

A+BforInput-OutputPractice(VI)

链接地址:

TimeLimit:

1Seconds    MemoryLimit:

32768K

以上几种情况的组合,可以参照如下网页。

参见:

HDOJ_1092(

1094A+BforInput-OutputPractice(VI)

ProblemDescription

Yourtaskistocalculatethesumofsomeintegers.

Input

Inputcontainsmultipletestcases,andonecaseoneline.EachcasestartswithanintegerN,andthenNintegersfollowinthesameline.

Output

ForeachtestcaseyoushouldoutputthesumofNintegersinoneline,andwithonelineofoutputforeachlineininput.

SampleInput

41234

512345

SampleOutput

10

15

参考答案

#include

intmain()

{

intn,a,b,i,j,sum;

sum=0;

while(scanf("%d\n",&n)!

=EOF)

{

for(j=0;j

{

scanf("%d",&a);

sum+=a;

}

printf("%d\n",sum);

sum=0;

}

return0;

}

 

输出

1、第一类输出

一个InputBlock对应一个OutputBlock,OutputBlock之间没有空行。

参见:

HDOJ_1089(

 

2、第二类输出

一个InputBlock对应一个OutputBlock,每个OutputBlock之后都有空行。

参见:

HDOJ_1095(

1095A+BforInput-OutputPractice(VII)

ProblemDescription

YourtaskistoCalculatea+b.

Input

Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.

Output

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.

SampleInput

15

1020

SampleOutput

6

30

参考答案

#include

intmain()

{

inta,b;

while(scanf("%d%d",&a,&b)!

=EOF)

printf("%d\n\n",a+b);

}

 

3、第三类输出

一个InputBlock对应一个OutputBlock,OutputBlock之间有空行。

参见:

HDOJ_1096(

1096A+BforInput-OutputPractice(VIII)

ProblemDescription

Yourtaskistocalculatethesumofsomeintegers.

Input

InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.

Output

Foreachgroupofinputinteg

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2