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

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

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

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

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

,&

a,&

b)!

=EOF)

printf("

%d\n"

a+b);

return0;

}

二、1002A+BProblemII

A+BProblemII

Time 

Limit:

2000/1000 

MS 

(Java/Others) 

Memory 

65536/32768 

(Java/Others)

Total 

Submission(s):

22627 

Accepted 

4035

Problem 

Description

have 

very 

simple 

problem 

for 

you. 

Given 

two 

integers 

and 

B, 

your 

job 

is 

to 

calculate 

the 

Sum 

of 

B.

The 

first 

line 

input 

contains 

an 

integer 

T(1<

=T<

=20) 

which 

means 

number 

test 

cases. 

Then 

lines 

follow, 

each 

consists 

positive 

integers, 

B. 

Notice 

that 

are 

large, 

you 

should 

not 

process 

them 

by 

using 

32-bit 

integer. 

You 

may 

assume 

length 

will 

exceed 

1000.

For 

case, 

output 

lines. 

"

Case 

#:

 

case. 

second 

equation 

Sum"

result 

Note 

there 

some 

spaces 

int 

equation. 

Output 

blank 

between 

cases.

Sample 

112233445566778899 

998877665544332211

1:

3

2:

998877665544332211 

111111*********1110

思路:

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

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

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

具体解题思路如下:

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

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

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

string.h>

stdlib.h>

intmain()

{

charstr1[1005],str2[1005];

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

inta[1005];

scanf("

%d"

n);

while(n--)

{

%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;

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

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

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

}

count++;

Case%d:

\n"

count);

%s+%s="

flag=0;

for(i=1004;

i--)

if(flag||a[i])

a[i]);

flag=1;

}

);

if(n!

=0)printf("

三、1089A+BforInput-OutputPractice(I)

A+BforInput-OutputPractice(I)

1089A+BforInput-OutputPractice(I)

YourtaskistoCalculatea+b.

Tooeasy?

!

Ofcourse!

Ispeciallydesignedtheproblemforacmbeginners.

Youmusthavefoundthatsomeproblemshavethesametitleswiththisone,yes,alltheseproblemsweredesignedforthesameaim.

Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.

15

1020

6

30

四、1090A+BforInput-OutputPractice(II)

A+BforInput-OutputPractice(II)

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

参见:

HDOJ_1090(

1090A+BforInput-OutputPractice(II)

Yourtaskistocalculatea+b.

InputcontainsanintegerNinthefirstline,andthenNlinesfollow.Eachlineconsistsofapairofintegersaandb,separatedbyaspace,onepairofintegersperline.

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput. 

Sampleinput

Sampleoutput

intn,i,a,b;

for(i=0;

i<

n;

i++)

scanf("

%d%d"

a,&

b);

printf("

五、1091A+BforInput-OutputPractice(III)

A+BforInput-OutputPractice(III)

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

HDOJ_1091(

1091A+BforInput-OutputPractice(III)

Yourtaskistocalculatea+b.

Inputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.

00

30

while(scanf("

b)!

=EOF&

&

(a!

=0||b!

=0))

printf("

if(a==0&

b==0)

break;

else

六、1092A+BforInput-OutputPractice(IV)

A+BforInput-OutputPractice(IV)

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

HDOJ_1092(

1092A+BforInput-OutputPractice(IV)

YourtaskistoCalculatethesumofsomeintegers.

Inputcontainsmultipletestcases.EachtestcasecontainsaintegerN,andthenNintegersfollowinthesameline.Atestcasestartingwith0terminatestheinputandthistestcaseisnottobeprocessed.

Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.

41234

512345

10

15

intn,sum,i,t;

&

n)!

=EOF&

n!

=0)

sum=0;

for(i=0;

i<

n;

i++)

t);

sum=sum+t;

sum);

七、1093A+BforInput-OutputPractice(V)

A+BforInput-OutputPractice(V)

1093A+BforInput-OutputPractice(V)

Yourtaskistocalculatethesumofsomeintegers.

InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.

Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.

#include<

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

sum=0;

=EOF)

for(j=0;

j<

b;

j++)

a);

sum+=a;

八、1094A+BforInput-OutputPractice(VI)

A+BforInput-OutputPractice(VI)

1094A+BforInput-OutputPractice(VI)

Inputcontainsmultipletestcases,andonecaseoneline.EachcasestartswithanintegerN,andthenNintegersfollowinthesameline.

ForeachtestcaseyoushouldoutputthesumofNintegersinoneline,andwithonelineofoutputforeachlineininput.

n)!

=EOF)

for(j=0;

j<

j++)

sum+=a;

sum);

输出

1、第一类输出

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

HDOJ_1089(

2、第二类输出

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

HDOJ_1095(

1095A+BforInput-OutputPractice(VII)

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.

while(scanf("

=EOF)

printf("

%d\n\n"

}

3、第三类输出

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

HDOJ_1096(

1096A+BforInput-OutputPractice(VIII)

Foreachgroupofinputinteg

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

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

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

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