杭电题目acm答案文档格式.docx
《杭电题目acm答案文档格式.docx》由会员分享,可在线阅读,更多相关《杭电题目acm答案文档格式.docx(55页珍藏版)》请在冰豆网上搜索。
>
main()
{
intn,i,sum;
sum=0;
while((scanf("
%d"
&
n)!
=-1))
{
for(i=0;
i<
=n;
i++)
sum+=i;
printf("
%d\n\n"
sum);
}
}
1089A+BforInput-OutputPractice(I)
YourtaskistoCalculatea+b.
Tooeasy!
Ofcourse!
Ispeciallydesignedtheproblemforacmbeginners.
Youmusthavefoundthatsomeproblemshavethesametitleswiththisone,yes,alltheseproblemsweredesignedforthesameaim.
Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.
15
1020
6
30
lcy
Recommend
JGShining
main()
inta,b;
while(scanf("
%d%d"
a,&
b)!
=EOF)
%d\n"
a+b);
1090A+BforInput-OutputPractice(II)
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.Eachlineconsistsofapairofintegersaandb,separatedbyaspace,onepairofintegersperline.
2
#defineM1000
voidmain()
{
inta,b,n,j[M],i;
Inputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.
00
scanf("
%d%d"
b);
while(!
(a==0&
&
b==0))
1092A+BforInput-OutputPractice(IV)
YourtaskistoCalculatethesumofsomeintegers.
Inputcontainsmultipletestcases.EachtestcasecontainsaintegerN,andthenNintegersfollowinthesameline.Atestcasestartingwith0terminatestheinputandthistestcaseisnottobeprocessed.
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.
41234
512345
0
10
15
#include<
intmain()
intn,sum,i,t;
=EOF&
n!
=0)
n;
t);
sum=sum+t;
1093A+BforInput-OutputPractice(V)
Yourtaskistocalculatethesumofsomeintegers.
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.
intn,a,b,i,j,sum;
=-1)
for(j=0;
j<
b;
j++)
a);
sum+=a;
1094A+BforInput-OutputPractice(VI)
Inputcontainsmultipletestcases,andonecaseoneline.EachcasestartswithanintegerN,andthenNintegersfollowinthesameline.
ForeachtestcaseyoushouldoutputthesumofNintegersinoneline,andwithonelineofoutputforeachlineininput.
[CopytoClipboard]
[SavetoFile]
1095A+BforInput-OutputPractice(VII)
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.
1096A+BforInput-OutputPractice(VIII)
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andyoumustnotethatthereisablanklinebetweenoutputs.
3
3123
inta,b,i,j,l[1000],k;
i);
getchar();
for(j=1;
=i;
l[j]=0;
for(k=1;
k<
=a;
k++)
l[j]+=b;
=i-1;
l[j]);
l[i]);
}
2000ASCII码排序
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
对于每组输入数据,输出一行,字符中间用一个空格分开。
qwe
asd
zxc
eqw
ads
cxz
Source
C语言程序设计练习
(一)
chara,b,c,d;
%c%c%c"
b,&
c)!
if(a>
=b)
if(c>
=a)
%c%c%c\n"
b,a,c);
elseif(b>
=c)
c,b,a);
elseif(b<
c)
b,c,a);
else
a,b,c);
elseif(c>
a,c,b);
elseif(a>
c,a,b);
2001计算两点间的距离
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
对于每组输入数据,输出一行,结果保留两位小数。
0001
0110
doublea,b,c,d,s;
%lf%lf%lf%lf"
c,&
d)!
s=sqrt((a-c)*(a-c)+(b-d)*(b-d));
%.2lf\n"
s);
}
2002计算球体积
根据输入的半径值,计算球的体积。
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
Hint
#definePI
doublea,v;
%lf"
a)!
v=4*PI*a*a*a/3;
%.3lf\n"
v);
2003求绝对值
求实数的绝对值。
输入数据有多组,每组占一行,每行包含一个实数。
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
123
doublea;
if(a<
0)
a=-a;
a);
2004成绩转换
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
输入数据有多组,每组占一行,由一个整数组成。
对于每组输入数据,输出一行。
如果输入数据不在0~100范围内,请输出一行:
“Scoreiserror!
”。
56
67
E
D
A
Scoreiserror!
intn;
if(n>
100||n<
0)printf("
\n"
);
elseif(n>
=90)printf("
A\n"
=80)printf("
B\n"
=70)printf("
C\n"
=60)printf("
D\n"
elseprintf("
E\n"
return0;
2005第几天
给定一个日期,输出这个日期是该年的第几天。
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sampleinput,另外,可以向你确保所有的输入数据是合法的。
对于每组输入数据,输出一行,表示该日期是该年的第几天。
1985/1/20
2006/3/12
20
71
inta,b,c,d,e,f,g;
%d/%d/%d"
if(b==1)
d=c;
elseif(b==2)
d=31+c;
elseif(b==3)
d=31+28+c;
elseif(b==4)
d=31+28+31+c;
elseif(b==5)
d=31+31+28+30+c;
elseif(b==6)
d=31+28+31+30+31+c;
elseif(b==7)
d=31+28+31+30+31+30+c;
elseif(b==8)
d=31+28+31+30+31+30+31+c;
elseif(b==9)
d=31+28+31+30+31+30+31+31+c;
elseif(b==10)
d=31+28+31+30+31+30+31+31+30+c;
elseif(b==11)
d=31+28+31+30+31+30+31+31+30+31+c;
elseif(b==12)
d=31+28+31+30+31+30+31+31+30+31+c+30;
e=a%100;
f=a%400;
g=a%4;
if(e==0)
if(f==0)
d=1+d;
else
d=d;
elseif(g=0)
d=