杭电acm部分题目及答案答案Word文档格式.docx
- 文档编号:22516078
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:20
- 大小:17.44KB
杭电acm部分题目及答案答案Word文档格式.docx
《杭电acm部分题目及答案答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《杭电acm部分题目及答案答案Word文档格式.docx(20页珍藏版)》请在冰豆网上搜索。
stdio.h>
main()
{
intn,i,sum;
sum=0;
while((scanf("
%d"
&
n)!
=-1))
{
for(i=0;
i<
=n;
i++)
sum+=i;
printf("
%d\n\n"
sum);
}
}
1089A+BforInput-OutputPractice(I)
YourtaskistoCalculatea+b.
Tooeasy?
!
Ofcourse!
Ispeciallydesignedtheproblemforacmbeginners.
Youmusthavefoundthatsomeproblemshavethesametitleswiththisone,yes,alltheseproblemsweredesignedforthesameaim.
Theinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.
15
1020
6
30
lcy
Recommend
JGShining
main()
inta,b;
while(scanf("
%d%d"
a,&
b)!
=EOF)
%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;
b);
%d%d"
a,b);
j[i]=a+b;
i=0;
while(i<
n)
j[i]);
i++;
}
1091A+BforInput-OutputPractice(III)
Inputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.
00
while(!
(a==0&
&
b==0))
1092A+BforInput-OutputPractice(IV)
YourtaskistoCalculatethesumofsomeintegers.
Inputcontainsmultipletestcases.EachtestcasecontainsaintegerN,andthenNintegersfollowinthesameline.Atestcasestartingwith0terminatestheinputandthistestcaseisnottobeprocessed.
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.
41234
512345
0
10
15
#include<
intmain()
intn,sum,i,t;
=EOF&
n!
=0)
t);
sum=sum+t;
1093A+BforInput-OutputPractice(V)
Yourtaskistocalculatethesumofsomeintegers.
InputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.
intn,a,b,i,j,sum;
=-1)
for(j=0;
j<
b;
j++)
a);
sum+=a;
1094A+BforInput-OutputPractice(VI)
Inputcontainsmultipletestcases,andonecaseoneline.EachcasestartswithanintegerN,andthenNintegersfollowinthesameline.
ForeachtestcaseyoushouldoutputthesumofNintegersinoneline,andwithonelineofoutputforeachlineininput.
[CopytoClipboard]
[SavetoFile]
1095A+BforInput-OutputPractice(VII)
Foreachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.
1096A+BforInput-OutputPractice(VIII)
Foreachgroupofinputintegersyoushouldoutputtheirsuminoneline,andyoumustnotethatthereisablanklinebetweenoutputs.
3
3123
inta,b,i,j,l[1000],k;
i);
getchar();
for(j=1;
=i;
l[j]=0;
for(k=1;
k<
=a;
k++)
l[j]+=b;
=i-1;
l[j]);
l[i]);
HowtoType
Pirateshavefinisheddevelopingthetypingsoftware.HecalledCathytotesthistypingsoftware.Sheisgoodatthinking.Aftertestingforseveraldays,shefindsthatifshetypesastringbysomeways,shewilltypethekeyatleast.Butshehasabadhabitthatifthecapslockison,shemustturnoffit,aftershefinishestyping.Nowshewantstoknowthesmallesttimesoftypingthekeytofinishtypingastring.
Thefirstlineisanintegert(t<
=100),whichisthenumberoftestcaseintheinputfile.Foreachtestcase,thereisonlyonestringwhichconsistsoflowercaseletteranduppercaseletter.Thelengthofthestringisatmost100.
Foreachtestcase,youmustoutputthesmallesttimesoftypingthekeytofinishtypingthisstring.
Pirates
HDUacm
HDUACM
8
string.h>
#defineMAX200
intarr[MAX][4];
charstr[MAX];
intletter(charch)
if(ch>
='
A'
ch<
Z'
)return1;
return0;
voidproc()
inti;
inttmp,min;
intlen=strlen(str);
len;
if(i==0)
if(letter(str[i])){arr[i][1]=2;
arr[i][2]=2;
else{arr[i][0]=1;
arr[i][3]=3;
else
if(letter(str[i])==letter(str[i-1]))
if(arr[i-1][0]){arr[i][0]=arr[i-1][0]+1;
arr[i][3]=arr[i-1][0]+3;
if(arr[i-1][1]){arr[i][1]=arr[i-1][1]+2;
arr[i][2]=arr[i-1][1]+2;
if(arr[i-1][2])
if(arr[i][0]>
arr[i-1][2]+1||!
arr[i][0])arr[i][0]=arr[i-1][2]+1;
if(arr[i][3]>
arr[i-1][2]+3||!
arr[i][3])arr[i][3]=arr[i-1][2]+3;
if(arr[i-1][3])
if(arr[i][1]>
arr[i-1][3]+2||!
arr[i][1])arr[i][1]=arr[i-1][3]+2;
if(arr[i][2]>
arr[i][2])arr[i][2]=arr[i-1][3]+2;
if(arr[i-1][0]){arr[i][1]=arr[i-1][0]+2;
arr[i][2]=arr[i-1][0]+2;
if(arr[i-1][1]){arr[i][0]=arr[i-1][1]+1;
arr[i][3]=arr[i-1][1]+3;
arr[i-1][2]+2||!
arr[i][1])arr[i][1]=arr[i-1][2]+2;
arr[i][2])arr[i][2]=arr[i-1][2]+2;
arr[i-1][3]+1||!
arr[i][0])arr[i][0]=arr[i-1][3]+1;
arr[i-1][3]+3||!
arr[i][3])arr[i][3]=arr[i-1][3]+3;
min=3*MAX;
if(letter(str[len-1]))
if(arr[len-1][0]){tmp=arr[len-1][0]+1;
if(tmp<
min)min=tmp;
if(arr[len-1][1]){tmp=arr[len-1][1];
if(arr[len-1][2]){tmp=arr[len-1][2]+1;
if(arr[len-1][3]){tmp=arr[len-1][3];
if(arr[len-1][0]){tmp=arr[len-1][0];
if(arr[len-1][1]){tmp=arr[len-1][1]+1;
if(arr[len-1][2]){tmp=arr[len-1][2];
if(arr[len-1][3]){tmp=arr[len-1][3]+1;
min);
//CapsShift:
0-00;
1-01;
2-10;
3-11
intnum;
num);
while(num--)
%s"
str);
memset(arr,0,strlen(str)*4*sizeof(int));
proc();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- acm 部分 题目 答案