Acm试题及答案.docx

上传人:b****5 文档编号:8312548 上传时间:2023-01-30 格式:DOCX 页数:54 大小:27.30KB
下载 相关 举报
Acm试题及答案.docx_第1页
第1页 / 共54页
Acm试题及答案.docx_第2页
第2页 / 共54页
Acm试题及答案.docx_第3页
第3页 / 共54页
Acm试题及答案.docx_第4页
第4页 / 共54页
Acm试题及答案.docx_第5页
第5页 / 共54页
点击查看更多>>
下载资源
资源描述

Acm试题及答案.docx

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

Acm试题及答案.docx

Acm试题及答案

Acm试题及答案

 

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;

1091A

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

 

?

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

?

SampleOutput

 

Hint

#definePI

?

Author

lcy

?

Source

C语言程序设计练习

(一)

?

Recommend

JGShining

解答:

#include<>

#definePI

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

?

SampleOutput

 

?

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>=60)printf("D\n");

elseprintf("E\n");

}

return0;

}

2005第几天

ProblemDescription

给定一个日期,输出这个日期是该年的第几天。

?

Input

输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sampleinput,另外,可以向你确保所有的输入数据是合法的。

?

Output

对于每组输入数据,输出一行,表示该日期是该年的第几天。

?

SampleInput

1985/1/20

2006/3/12

?

SampleOutput

20

71

?

Author

lcy

?

Source

C语言程序设计练习

(一)

?

Recommend

JGShining

解答:

#include<>

main()

{

inta,b,c,d,e,f,g;

while(scanf("%d/%d/%d",&a,&b,&c)!

=EOF)

{

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=d+1;

else

d=d;

printf("%d\n",d);

}

}

2006求奇数的乘积

ProblemDescription

给你n个整数,求他们中所有奇数的乘积。

?

Input

输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表

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

当前位置:首页 > 初中教育 > 学科竞赛

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1