Acm试题及答案.docx

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

Acm试题及答案.docx

《Acm试题及答案.docx》由会员分享,可在线阅读,更多相关《Acm试题及答案.docx(65页珍藏版)》请在冰点文库上搜索。

Acm试题及答案.docx

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)12

1095A+BforInput-OutputPractice(VII)13

1096A+BforInput-OutputPractice(VIII)14

2000ASCII码排序16

2001计算两点间的距离17

2002计算球体积19

2003求绝对值20

2004成绩转换21

2005第几天?

22

2006求奇数的乘积24

2007平方和与立方和26

2008数值统计27

2009求数列的和28

2010水仙花数29

2011多项式求和31

2012素数判定33

2014青年歌手大奖赛_评委会打分34

2015偶数求和36

2016数据的交换输出38

2017字符串统计40

2019数列有序!

41

2020绝对值排序43

2021发工资咯:

)45

2033人见人爱A+B46

2039三角形48

2040亲和数49

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((scanf("%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

 

Recommend

JGShining

解答:

#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++;

printf("\n");

}

}

1091A+BforInput-OutputPractice(III)

ProblemDescription

YourtaskistoCalculatea+b.

Input

Inputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.

Output

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.

SampleInput

15

1020

00

SampleOutput

6

30

 

Author

lcy

Recommend

JGShining

解答:

#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

0

 

SampleOutput

10

15

 

Author

lcy

 

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

15

 

Author

lcy

解答:

#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

 

Author

lcy

 

Recommend

JGShining

解答:

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

}

}

1095A+BforInput-OutputPractice(VII)

ProblemDescription

YourtaskistoCalculatea+b.

 

Input

Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.

 

Output

Foreachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.

 

SampleInput

15

1020

 

SampleOutput

6

30

 

Author

lcy

 

Recommend

JGShining

解答:

#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

41234

512345

3123

 

SampleOutput

10

15

6

 

Author

lcy

 

Recommend

JGShining

解答:

intmain()

{

inta,b,i,j,l[1000],k;

scanf("%d",&i);

getchar();

for(j=1;j<=i;j++)

l[j]=0;

for(j=1;j<=i;j++)

{

scanf("%d",&a);

getchar();

for(k=1;k<=a;k++)

{

scanf("%d",&b);

getchar();

l[j]+=b;

}

}

for(j=1;j<=i-1;j++)

printf("%d\n\n",l[j]);

printf("%d\n",l[i]);

}

2000ASCII码排序

ProblemDescription

输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

 

Input

输入数据有多组,每组占一行,有三个字符组成,之间无空格。

 

Output

对于每组输入数据,输出一行,字符中间用一个空格分开。

 

SampleInput

qwe

asd

zxc

 

SampleOutput

eqw

ads

cxz

 

Author

lcy

 

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(b

printf("%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

1

1.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

对于每组输入数据,输出一行。

如果输入数据不在0~100范围内,请输出一行:

“Scoreiserror!

”。

 

SampleInput

56

67

100

123

 

SampleOutput

E

D

A

Scoreiserror!

 

Author

lcy

 

Source

C语言程序设计练习

(一)

 

Recommend

JGShining

解答:

#include

intmain()

{

intn;

while(scanf("%d",&n)!

=EOF)

{

if(n>100||n<0)printf("Scoreiserror!

\n");

elseif(n>=90)printf("A\n");

elseif(n>=80)printf("B\n");

elseif(n>=70)printf("C\n");

elseif(n>

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

当前位置:首页 > 表格模板

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

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