部分ACM题目与答案.docx
- 文档编号:4962257
- 上传时间:2022-12-12
- 格式:DOCX
- 页数:58
- 大小:42.82KB
部分ACM题目与答案.docx
《部分ACM题目与答案.docx》由会员分享,可在线阅读,更多相关《部分ACM题目与答案.docx(58页珍藏版)》请在冰豆网上搜索。
部分ACM题目与答案
1089A+BforInput-Output Practice (I)ﻩ4
1090A+BforInput-Output Practice(II)6
1091 A+BforInput-OutputPractice(III)ﻩ8
1092A+BforInput-OutputPractice(IV)ﻩ9
1093A+B forInput-OutputPractice(V)ﻩ11
1096A+Bfor Input-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
2014青年歌手大奖赛_评委会打分34
2015偶数求与36
2016数据得交换输出ﻩ38
2021发工资咯:
)45
2033人见人爱A+Bﻩ46
2039三角形ﻩ48
2040亲与数49
1001 SumProblem
Problem Description
Hey,weleto HDOJ(HangzhouDianzi University Online Judge)、ﻫ
Inthisproblem,yourtaskistocalculate SUM(n)=1+2 +3+、、、+n、
Input
Theinputwillconsist ofa series ofintegers n,one integerper line、
Output
Foreachcase,outputSUM(n) inone line,followedbya blankline、Youmayassumetheresult will bein the rangeof32-bit signedinteger、
Sample Input
1
100
SampleOutput
1
5050
Author
DOOM III
解答:
#include
main()
{
int n,i,sum;
sum=0;
while((scanf("%d",&n)!
=-1))
{
sum=0;
for(i=0;i<=n;i++)
sum+=i;
printf("%d\n\n",sum);
}
}
1089 A+Bfor Input-OutputPractice(I)
ProblemDescription
YourtaskistoCalculatea+b、
Tooeasy?
!
Ofcourse!
Ispeciallydesignedthe problemforacmbeginners、 ﻫYou musthave foundthatsomeproblems have thesametitles withthis one,yes, all these problemsweredesignedforthesameaim、
Input
Theinput willconsistofaseries ofpairsofintegersaand b,separated byaspace,one pairof integersperline、
Output
Foreachpair ofinputintegersaand byoushouldoutputthesum ofaandbinoneline, and withonelineof output foreachlineininput、
SampleInput
15
1020
Sample Output
6
30
Author
lcy
Remend
JGShining
解答:
#include
main()
{
int a,b;
while(scanf("%d%d",&a,&b)!
=EOF)
printf("%d\n",a+b);
}
1090A+BforInput-OutputPractice(II)
ProblemDescription
Your taskistoCalculatea+ b、
Input
InputcontainsanintegerNinthefirstline,andthenNlinesfollow、 Eachlineconsistsofapair ofintegersaandb,separated byaspace,one pairofintegersperline、
Output
For eachpairofinputintegers a andbyoushouldoutputthesum ofaandbinoneline,and withoneline ofoutput foreachlineininput、
SampleInput
2
15
1020
SampleOutput
6
30
Author
lcy
Remend
JGShining
解答:
#include
#defineM1000
voidmain()
{
inta,b,n,j[M],i;
//printf("pleaseinput n:
\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<n) { printf("%d",j[i]); i++; printf("\n"); } } 1091 A+BforInput-OutputPractice(III) ProblemDescription YourtaskistoCalculatea +b、 Input Inputcontainsmultipletestcases、Each testcasecontainsa pairofintegersaandb,onepairof integersper line、Atestcasecontaining00 terminatesthe inputandthistestcaseis nottobeprocessed、 Output For eachpairofinputintegersaandb youshouldoutputthesum of aandbinoneline,andwith oneline ofoutputforeach linein input、 SampleInput 15 1020 00 Sample Output 6 30 Author lcy Remend 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) Problem Description Your taskistoCalculatethesumof someintegers、 Input Inputcontainsmultipletestcases、Eachtestcasecontainsa integer N,andthenNintegersfollowinthesame line、 Atest casestartingwith 0terminatestheinputandthistest case isnotto beprocessed、 Output Foreachgroupofinput integersyoushouldoutputtheirsuminoneline,and withonelineofoutputforeachlineininput、 Sample Input 41234 5123 45 0 SampleOutput 10 15 Author lcy Remend 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 Yourtask istocalculatethe sumofsome integers、 Input Input containsanintegerNinthefirst line,andthenN linesfollow、 Eachline starts withaintegerM, and thenMintegers followinthesameline、 Output Foreach groupofinputintegers you shouldoutputtheirsum inoneline,andwithone lineofoutput foreachline ininput、 Sample Input 2 4 1234 512345 Sample Output 10 15 Author lcy 解答: #include<stdio、h> main() { intn,a,b,i,j,sum; sum=0; while(scanf("%d\n",&n)! =-1) { for(i=0;i<n;i++) { scanf("%d",&b); for(j=0;j { scanf("%d",&a); sum+=a; } printf("%d\n",sum); sum=0; } } } 1094A+BforInput-OutputPractice(VI) Problem Description Your taskistocalculatethesumofsomeintegers、 Input Inputcontainsmultipletest cases, andonecase oneline、Eachcasestartswith an integerN,andthen Nintegers follow inthesame line、 Output Foreach testcaseyoushouldoutputthesumofNintegersin oneline,andwithone lineof outputforeachlineininput、 SampleInput 41234 5 12345 SampleOutput 10 15 Author lcy Remend JGShining 解答: #include main() { int n,a,b,i,j,sum; sum=0; while(scanf("%d\n",&n)! =-1) { for(j=0;j<n;j++) { scanf("%d",&a); sum+=a; } printf("%d\n",sum); sum=0; } } [CopytoClipboard] [SavetoFile] ﻮ1095A+Bfor Input-OutputPractice(VII) Problem Description YourtaskistoCalculatea+b、 Input Theinputwillconsistofa seriesof pairsofintegersaandb,separated byaspace,onepairofintegersperline、 Output Foreach pair ofinput integersa andb youshouldoutputthesumofaandb,andfollowedby ablankline、 SampleInput 15 1020 SampleOutput 6 30 Author lcy Remend JGShining ﻮ解答: #include<stdio、h> main() { inta,b; while(scanf("%d%d",&a,&b)! =EOF) printf("%d\n\n",a+b); } 1096A+BforInput-Output Practice(VIII) ProblemDescription Yourtask istocalculate thesum ofsome integers、 Input Inputcontainsaninteger Nin the first line,andthenNlinesfollow、Each linestartswitha integerM, andthen Mintegers followinthesame line、 Output Foreachgroupofinputintegersyoushouldoutputtheirsumin oneline,andyoumustnotethatthereisa blank line betweenoutputs、 SampleInput 3 4123 4 5 1 2345 3123 SampleOutput 10 15 6 Author lcy Remend JGShining 解答: intmain() { int a,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语言程序设计练习 (一) Remend 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<c) 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); else if(a>c) printf("%c %c%c\n",c,a,b); } } } 2001计算两点间得距离 ProblemDescription 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间得距离。 Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。 Output 对于每组输入数据,输出一行,结果保留两位小数。 SampleInput 0 001 011 0 SampleOutput 1、00 1、41 Author lcy Source C语言程序设计练习 (一) Remend 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计算球体积 Problem Description 根据输入得半径值,计算球得体积。 Input 输入数据有多组,每组占一行,每行包括一个实数,表示球得半径。 Output 输出对应得球得体积,对于每组输入数据,输出一行,计算结果保留三位小数。 SampleInput 1 1、5 SampleOutput 4、189 14、137 Hint #definePI3、1415927 Author lcy Source C语言程序设计练习 (一) Remend JGShining 解答: #include<stdio、h> #definePI 3、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语言程序设计练习 (一) Remend JGShining 解答: #include<stdio、h> 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范围内,请输出一行: “Scoreis error! ”。 SampleInput 56 67 100 123 SampleOutput E D A Scoreiserror! Author lcy Source C语言程序设计练习 (一) Remend JGShining 解答: #include intmain() { intn; while(scanf("%d",&n)! =EOF) { if(n>100||n<0)printf("Scor
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 部分 ACM 题目 答案