杭电ACM部分题目答案Word格式.docx
《杭电ACM部分题目答案Word格式.docx》由会员分享,可在线阅读,更多相关《杭电ACM部分题目答案Word格式.docx(61页珍藏版)》请在冰点文库上搜索。
![杭电ACM部分题目答案Word格式.docx](https://file1.bingdoc.com/fileroot1/2023-5/7/29ecafc5-c96f-46ba-978f-2b45dc63e581/29ecafc5-c96f-46ba-978f-2b45dc63e5811.gif)
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
5050
Author
DOOMIII
解答:
#include<
stdio.h>
main()
{
intn,i,sum;
sum=0;
while((seanf("
%d"
,&
n)!
=-1))
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.
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.
SampleInput
15
1020
6
30
lcy
Recommend
JGShining
inta,b;
while(scanf("
%d%d"
&
a,&
b)!
=EOF)printf("
%d\n"
a+b);
1090A+BforInput-OutputPractice
(II)
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.Eachlineconsistsofapairofintegersaandb,separatedbyaspace,onepairofintegersperline.
2
#defineM1000
voidmain()
inta,b,n,j[M],i;
//printf("
pleaseinputn:
\n"
);
scanf("
n);
n;
scanf
("
b);
//printf("
%d%d"
a,b);
j[i
]=a+b;
}i
=0;
while(
i<
n)
printf
j[i]);
i++
J
1091A+BforInput-OutputPractice
(III)
Inputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.
15
102000
inta
b;
scanf
while
(!
(a==0&
&
b==0))
b)
1092A+BforInput-OutputPractice
(IV)
YourtaskistoCalculatethesumofsomeintegers.
Inputcontainsmultipletestcases.EachtestcasecontainsaintegerN,andthenNintegersfollowinthesameline.Atestcasestartingwith0terminatestheinputandthistestcaseisnottobeprocessed.
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.
41234
512345
10
Icy
Recommend
JGShining
#include<
intmain()
intn,sum,i,t;
&
n)!
=EOF&
n!
=0)
scanf("
t);
sum=sum+t;
1093A+BforInput-OutputPractice
(V)
Yourtaskistocalculatethesumofsomeintegers.
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.
41234
512345
intn,a,b,i,j,sum;
while(scanf("
,&
=-1)
for(j=0;
j<
b;
j++)
a);
sum+=a;
1094A+BforInput-OutputPractice
(VI)
Yourtaskistocalculatethesumofsomeintegers.
Inputcontainsmultipletestcases,andonecaseoneline.EachcasestartswithanintegerN,andthenNintegersfollowinthesameline.
ForeachtestcaseyoushouldoutputthesumofNintegersinoneline,andwithonelineofoutputforeachlineininput.
[CopytoClipboard][SavetoFile]
1095A+BforInput-OutputPractice
(VII)
Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.
=EOF)
1096A+BforInput-OutputPractice
(VIII)
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andyoumustnotethatthereisablanklinebetweenoutputs.
3
解答:
intmain
()
int
a,b,i,j,l[1000],
i);
getchar();
for
(j=1;
=i;
l
[j]=0;
k;
scanfgetcharfor
();
(k=1;
k<
=a;
k++)
scanfgetcharl
();
[j]+=b;
}for
printfprintf
(j
=1;
=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)!
=EOF){
if(a>
=b)
if(c>
=a)
%c%c%c\n"
b,
a,
c);
elseif
(b>
=c)
c,
b,
a);
(b<
c)
c,
else{
a,b,c);
(c>
a,c,b);
(a>
c,a,b);
2001计算两点间的距离
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔
开。
对于每组输入数据,输出一行,结果保留两位小数。
0001
0110
1.00
1.41
#include<
math.h>
doublea,b,c,d,s;
%lf%lf%lf%lf"
b,&
c,&
d)!
s=sqrt((a-c)*(a-c)+(b-d)*(b-d));
%.2lf\n"
s);
2002计算球体积
根据输入的半径值,计算球的体积。
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
11.5
4.189
14.137
Hint
#definePI3.1415927
doublea,v;
%lf"
a)!
v=4*PI*a*a*a/3;
%.3lf\n"
v);
2003求绝对值
求实数的绝对值。
输入数据有多组,每组占一行,每行包含一个实数。
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
123
-234.00
123.00
234.00
doublea;
if(a<
0)
a=-a;
a);
2004成绩转换
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
输入数据有多组,每组占一行,由一个整数组成。
"
Scoreis
对于每组输入数据,输出一行。
如果输入数据不在0~100范围内,请输出一行:
error!
。
”
56
67
E
D
A
Scoreiserror!
intmain()
if(n>
100||n<
0)printf
\n
(n>
=90)printf
A\n"
=80)printf
B\n"