杭电OJ的输入输出格式题Word格式.docx
《杭电OJ的输入输出格式题Word格式.docx》由会员分享,可在线阅读,更多相关《杭电OJ的输入输出格式题Word格式.docx(28页珍藏版)》请在冰点文库上搜索。
,&
a,&
b)!
=EOF)
printf("
%d\n"
a+b);
return0;
}
二、1002A+BProblemII
A+BProblemII
Time
Limit:
2000/1000
MS
(Java/Others)
Memory
65536/32768
K
(Java/Others)
Total
Submission(s):
22627
Accepted
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
+
B.
The
first
line
input
contains
an
integer
T(1<
=T<
=20)
which
means
number
test
cases.
Then
T
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
B
=
Sum"
result
Note
there
some
spaces
int
equation.
Output
blank
between
cases.
Sample
1
112233445566778899
998877665544332211
1:
2
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