杭电ACM部分题目答案.docx
《杭电ACM部分题目答案.docx》由会员分享,可在线阅读,更多相关《杭电ACM部分题目答案.docx(61页珍藏版)》请在冰豆网上搜索。
杭电ACM部分题目答案
杭电ACM
1001SumProblem2
1089A+BforInput-OutputPractice(I)4
1090A+BforInput-OutputPractice(II)6
1091A+BforInput-OutputPractice(III)8
1092A+BforInput-OutputPractice(IV)9
1093A+BforInput-OutputPractice(V)11
1094A+BforInput-OutputPractice(VI)13
1095A+BforInput-OutputPractice(VII)14
1096A+BforInput-OutputPractice(VIII)16
2000ASCII码排序17
2001计算两点间的距离19
2002计算球体积20
2003求绝对值21
2004成绩转换22
2005第几天?
24
2006求奇数的乘积26
2007平方和与立方和27
2008数值统计28
2009求数列的和30
2010水仙花数31
2011多项式求和33
2012素数判定34
2014青年歌手大奖赛_评委会打分36
2015偶数求和38
2016数据的交换输出40
2017字符串统计42
2019数列有序!
43
2020绝对值排序45
2021发工资咯:
)46
2033人见人爱A+B48
2039三角形50
2040亲和数51
姓名:
郑春杰
班级:
电商1001
学号:
1010504134
1001SumProblem
ProblemDescription
Hey,welcometoHDOJ(HangzhouDianziUniversityOnlineJudge).
Inthisproblem,yourtaskistocalculateSUM(n)=1+2+3+...+n.
Input
Theinputwillconsistofaseriesofintegersn,oneintegerperline.
Output
Foreachcase,outputSUM(n)inoneline,followedbyablankline.Youmayassumetheresultwillbeintherangeof32-bitsignedinteger.
SampleInput
1
100
SampleOutput
1
5050
Author
DOOMIII
解答:
#include
main()
{
intn,i,sum;
sum=0;
while((seanf("%d",&n)!
=-1))
{
sum=0;
for(i=0;i<=n;i++)
sum+=i;
printf("%d\n\n",sum);
}
}
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
Author
lcy
Recommend
JGShining
解答:
#include
main()
{
inta,b;
while(scanf("%d%d",&a,&b)!
=EOF)printf("%d\n",a+b);
}
1090A+BforInput-OutputPractice
(II)
ProblemDescription
YourtaskistoCalculatea+b.
Input
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.Eachlineconsistsofapairofintegersaandb,separatedbyaspace,onepairofintegersperline.
Output
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.
SampleInput
2
15
1020
SampleOutput
6
30
Author
lcy
解答:
#include
#defineM1000
voidmain()
{
inta,b,n,j[M],i;//printf("pleaseinputn:
\n");scanf("%d",&n);
for(i=0;i{
scanf
("%d%d",&a,&b);
//printf("%d%d",a,b);
j[i
]=a+b;
}i
=0;
while(
i{
printf
("%d",j[i]);
i++
J
printf
("\n");
}
1091A+BforInput-OutputPractice
(III)
ProblemDescription
YourtaskistoCalculatea+b.
Input
Inputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.
Output
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.
SampleInput
15
102000
SampleOutput
6
30
Author
lcy
解答:
#include
main()
{
inta
b;
scanf
("%d%d",&a,&b);
while
(!
(a==0&&b==0))
{
printf
("%d\n",a+b);
scanf
("%d%d",&a,&b)
}
}
1092A+BforInput-OutputPractice
(IV)
ProblemDescription
YourtaskistoCalculatethesumofsomeintegers.
Input
Inputcontainsmultipletestcases.EachtestcasecontainsaintegerN,andthenNintegersfollowinthesameline.Atestcasestartingwith0terminatestheinputandthistestcaseisnottobeprocessed.
Output
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.
SampleInput
41234
512345
SampleOutput
10
15
Author
Icy
Recommend
JGShining
解答:
#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)
ProblemDescription
Yourtaskistocalculatethesumofsomeintegers.
Input
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.
Output
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.
SampleInput
2
41234
512345
SampleOutput
10
解答:
#include
main()
{
intn,a,b,i,j,sum;
sum=0;
while(scanf("%d\n",&n)!
=-1)
{
for(i=0;i{
scanf("%d",&b);
for(j=0;j
{
scanf("%d",&a);
sum+=a;
}
printf("%d\n",sum);
sum=0;
}
}
}
1094A+BforInput-OutputPractice
(VI)
ProblemDescription
Yourtaskistocalculatethesumofsomeintegers.
Input
Inputcontainsmultipletestcases,andonecaseoneline.EachcasestartswithanintegerN,andthenNintegersfollowinthesameline.
Output
ForeachtestcaseyoushouldoutputthesumofNintegersinoneline,andwithonelineofoutputforeachlineininput.
SampleInput
41234
512345
SampleOutput
10
15
解答:
#include
main()
{
intn,a,b,i,j,sum;
sum=0;
while(scanf("%d\n",&n)!
=-1)
{
for(j=0;j{
scanf("%d",&a);
sum+=a;
}
printf("%d\n",sum);
sum=0;
}
}
[CopytoClipboard][SavetoFile]
1095A+BforInput-OutputPractice
(VII)
ProblemDescription
YourtaskistoCalculatea+b.
Input
Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.
Output
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.
SampleInput
15
1020
SampleOutput
6
30
解答:
#include
main()
{
inta,b;
while(scanf("%d%d",&a,&b)!
=EOF)
printf("%d\n\n",a+b);
}
1096A+BforInput-OutputPractice
(VIII)
ProblemDescription
Yourtaskistocalculatethesumofsomeintegers.
Input
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.
Output
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andyoumustnotethatthereisablanklinebetweenoutputs.
SampleInput
3
SampleOutput
10
Author
Icy
Recommend
JGShining
解答:
intmain
()
{
int
a,b,i,j,l[1000],
scanf
("%d",&i);
getchar();
for
(j=1;j<=i;j++)
l
[j]=0;
for
(j=1;j<=i;j++)
k;
{
scanfgetcharfor
{
("%d",&a);
();
(k=1;k<=a;k++)
scanfgetcharl
("%d",&b);
();
[j]+=b;
}for
printfprintf
(j
=1;j<=i-1;j++)
("%d\n\n",l[j]);
("%d\n",l[i]);
2000ASCII码排序
ProblemDescription
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
SampleInput
qwe
asd
zxc
SampleOutput
eqw
ads
cxz
Author
Icy
Source
c语言程序设计练习
(一)
Recommend
JGShining
解答:
#include
main()
{
chara,b,c,d;
while(scanf("%c%c%c",&a,&b,&c)!
=EOF){
getchar();
if(a>=b)
{
if(c>=a)
printf
("%c%c%c\n"
b,
a,
c);
elseif
(b>=c)
printf
("%c%c%c\n"
c,
b,
a);
elseif
(bprintf
("%c%c%c\n"
b,
c,
a);
else{
if(c>=b)
printf
("%c%c%c\n"
a,b,c);
elseif
(c>=a)
printf
("%c%c%c\n"
a,c,b);
elseif
(a>c)
printf
("%c%c%c\n"
c,a,b);
2001计算两点间的距离
ProblemDescription
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔
开。
Output
对于每组输入数据,输出一行,结果保留两位小数。
SampleInput
0001
0110
SampleOutput
1.00
1.41
Author
lcy
Source
c语言程序设计练习
(一)
Recommend
JGShining
解答:
#include
#include
main()
{
doublea,b,c,d,s;
while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d)!
=EOF)
{
s=sqrt((a-c)*(a-c)+(b-d)*(b-d));
printf("%.2lf\n",s);
}
}
2002计算球体积
ProblemDescription
根据输入的半径值,计算球的体积。
Input
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
SampleInput
11.5
SampleOutput
4.189
14.137
Hint
#definePI3.1415927
Author
lcy
Source
c语言程序设计练习
(一)
Recommend
JGShining
解答:
#include
#definePI3.1415927
main()
{
doublea,v;
while(scanf("%lf",&a)!
=EOF)
{
v=4*PI*a*a*a/3;
printf("%.3lf\n",v);
}
}
2003求绝对值
ProblemDescription
求实数的绝对值。
Input
输入数据有多组,每组占一行,每行包含一个实数。
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
SampleInput
123
-234.00
SampleOutput
123.00
234.00
Author
lcy
Source
c语言程序设计练习
(一)
Recommend
JGShining
解答:
#include
main()
{
doublea;
while(scanf("%lf",&a)!
=EOF)
{
if(a<0)
a=-a;
printf("%.2lf\n",a);
}
}
2004成绩转换
ProblemDescription
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
Input
输入数据有多组,每组占一行,由一个整数组成。
Output
"Scoreis
对于每组输入数据,输出一行。
如果输入数据不在0~100范围内,请输出一行:
error!
。
”
SampleInput
56
67
100
123
SampleOutput
E
D
A
Scoreiserror!
Author
lcy
Source
c语言程序设计练习
(一)
Recommend
JGShining
解答:
#includeintmain()
{
if(n>100||n<0)printf
("Scoreiserror!
\n
elseif
(n>=90)printf
("A\n");
elseif
(n>=80)printf
("B\n");
elseif