杭電題目acm答案_第1頁
杭電題目acm答案_第2頁
杭電題目acm答案_第3頁
杭電題目acm答案_第4頁
杭電題目acm答案_第5頁
已閱讀5頁,還剩33頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

./選修課考試作業(yè)TOC\o"1-1"\h\z\u1001SumProblem21089A+BforInput-OutputPractice<I>41090A+BforInput-OutputPractice<II>61091A+BforInput-OutputPractice<III>81092A+BforInput-OutputPractice<IV>91093A+BforInput-OutputPractice<V>111094A+BforInput-OutputPractice<VI>121095A+BforInput-OutputPractice<VII>131096A+BforInput-OutputPractice<VIII>142000ASCII碼排序162001計算兩點間的距離172002計算球體積192003求絕對值202004成績轉(zhuǎn)換212005第幾天?222006求奇數(shù)的乘積242007平方和與立方和262008數(shù)值統(tǒng)計272009求數(shù)列的和282010水仙花數(shù)292011多項式求和312012素數(shù)判定332014青年歌手大獎賽_評委會打分342015偶數(shù)求和362016數(shù)據(jù)的交換輸出382017字符串統(tǒng)計402019數(shù)列有序!412020絕對值排序432021發(fā)工資咯:452033人見人愛A+B462039三角形482040親和數(shù)49:春杰班級:電商1001學(xué)號:1010504134.1001SumProblemProblemDescriptionHey,welcometoHDOJ<HangzhouDianziUniversityOnlineJudge>.

Inthisproblem,yourtaskistocalculateSUM<n>=1+2+3+...+n.InputTheinputwillconsistofaseriesofintegersn,oneintegerperline.OutputForeachcase,outputSUM<n>inoneline,followedbyablankline.Youmayassumetheresultwillbeintherangeof32-bitsignedinteger.SampleInput1100SampleOutput15050AuthorDOOMIII解答:#include<stdio.h>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>ProblemDescriptionYourtaskistoCalculatea+b.

Tooeasy?!Ofcourse!Ispeciallydesignedtheproblemforacmbeginners.

Youmusthavefoundthatsomeproblemshavethesametitleswiththisone,yes,alltheseproblemsweredesignedforthesameaim.InputTheinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.OutputForeachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.SampleInput151020SampleOutput630AuthorlcyRecommendJGShining解答:#include<stdio.h>main<>{inta,b;while<scanf<"%d%d",&a,&b>!=EOF>printf<"%d\n",a+b>;}.1090A+BforInput-OutputPractice<II>ProblemDescriptionYourtaskistoCalculatea+b.InputInputcontainsanintegerNinthefirstline,andthenNlinesfollow.Eachlineconsistsofapairofintegersaandb,separatedbyaspace,onepairofintegersperline.OutputForeachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.SampleInput2151020SampleOutput630AuthorlcyRecommendJGShining解答:#include<stdio.h>#defineM1000voidmain<>{inta,b,n,j[M],i;//printf<"pleaseinputn:\n">;scanf<"%d",&n>;for<i=0;i<n;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">;}}.1091A+BforInput-OutputPractice<III>ProblemDescriptionYourtaskistoCalculatea+b.InputInputcontainsmultipletestcases.Eachtestcasecontainsapairofintegersaandb,onepairofintegersperline.Atestcasecontaining00terminatestheinputandthistestcaseisnottobeprocessed.OutputForeachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputforeachlineininput.SampleInput15102000SampleOutput630AuthorlcyRecommendJGShining解答:#include<stdio.h>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>ProblemDescriptionYourtaskistoCalculatethesumofsomeintegers.InputInputcontainsmultipletestcases.EachtestcasecontainsaintegerN,andthenNintegersfollowinthesameline.Atestcasestartingwith0terminatestheinputandthistestcaseisnottobeprocessed.OutputForeachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.SampleInput412345123450SampleOutput1015AuthorlcyRecommendJGShining解答:#include<stdio.h>intmain<>{intn,sum,i,t;while<scanf<"%d",&n>!=EOF&&n!=0>{sum=0;for<i=0;i<n;i++>{scanf<"%d",&t>;sum=sum+t;}printf<"%d\n",sum>;}}.1093A+BforInput-OutputPractice<V>ProblemDescriptionYourtaskistocalculatethesumofsomeintegers.InputInputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.OutputForeachgroupofinputintegersyoushouldoutputtheirsuminoneline,andwithonelineofoutputforeachlineininput.SampleInput241234512345SampleOutput1015Authorlcy解答:#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<b;j++>{scanf<"%d",&a>;sum+=a;}printf<"%d\n",sum>;sum=0;}}}.1094A+BforInput-OutputPractice<VI>ProblemDescriptionYourtaskistocalculatethesumofsomeintegers.InputInputcontainsmultipletestcases,andonecaseoneline.EachcasestartswithanintegerN,andthenNintegersfollowinthesameline.OutputForeachtestcaseyoushouldoutputthesumofNintegersinoneline,andwithonelineofoutputforeachlineininput.SampleInput41234512345SampleOutput1015AuthorlcyRecommendJGShining解答:#include<stdio.h>main<>{intn,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+BforInput-OutputPractice<VII>ProblemDescriptionYourtaskistoCalculatea+b.InputTheinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.OutputForeachpairofinputintegersaandbyoushouldoutputthesumofaandb,andfollowedbyablankline.SampleInput151020SampleOutput630AuthorlcyRecommendJGShining解答:#include<stdio.h>main<>{inta,b;while<scanf<"%d%d",&a,&b>!=EOF>printf<"%d\n\n",a+b>;}1096A+BforInput-OutputPractice<VIII>ProblemDescriptionYourtaskistocalculatethesumofsomeintegers.InputInputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.OutputForeachgroupofinputintegersyoushouldoutputtheirsuminoneline,andyoumustnotethatthereisablanklinebetweenoutputs.SampleInput3412345123453123SampleOutput10156AuthorlcyRecommendJGShining解答: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輸入數(shù)據(jù)有多組,每組占一行,有三個字符組成,之間無空格。Output對于每組輸入數(shù)據(jù),輸出一行,字符中間用一個空格分開。SampleInputqweasdzxcSampleOutputeqwadscxzAuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>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>;elseif<a>c>printf<"%c%c%c\n",c,a,b>;}}}2001計算兩點間的距離ProblemDescription輸入兩點坐標(biāo)〔X1,Y1,〔X2,Y2,計算并輸出兩點間的距離。Input輸入數(shù)據(jù)有多組,每組占一行,由4個實數(shù)組成,分別表示x1,y1,x2,y2,數(shù)據(jù)之間用空格隔開。Output對于每組輸入數(shù)據(jù),輸出一行,結(jié)果保留兩位小數(shù)。SampleInput00010110SampleOutput1.001.41AuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>#include<math.h>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根據(jù)輸入的半徑值,計算球的體積。Input輸入數(shù)據(jù)有多組,每組占一行,每行包括一個實數(shù),表示球的半徑。Output輸出對應(yīng)的球的體積,對于每組輸入數(shù)據(jù),輸出一行,計算結(jié)果保留三位小數(shù)。SampleInput11.5SampleOutput4.18914.137Hint#definePI3.1415927AuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>#definePI3.1415927main<>{doublea,v;while<scanf<"%lf",&a>!=EOF>{v=4*PI*a*a*a/3;printf<"%.3lf\n",v>;}}2003求絕對值ProblemDescription數(shù)的絕對值。Input輸入數(shù)據(jù)有多組,每組占一行,每行包含一個實數(shù)。Output對于每組輸入數(shù)據(jù),輸出它的絕對值,要求每組數(shù)據(jù)輸出一行,結(jié)果保留兩位小數(shù)。SampleInput123-234.00SampleOutput123.00234.00AuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>main<>{doublea;while<scanf<"%lf",&a>!=EOF>{if<a<0>a=-a;printf<"%.2lf\n",a>;}}2004成績轉(zhuǎn)換ProblemDescription輸入一個百分制的成績t,將其轉(zhuǎn)換成對應(yīng)的等級,具體轉(zhuǎn)換規(guī)則如下:

90~100為A;

80~89為B;

70~79為C;

60~69為D;

0~59為E;Input輸入數(shù)據(jù)有多組,每組占一行,由一個整數(shù)組成。Output對于每組輸入數(shù)據(jù),輸出一行。如果輸入數(shù)據(jù)不在0~100圍,請輸出一行:"Scoreiserror!"。SampleInput5667100123SampleOutputEDAScoreiserror!AuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>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輸入數(shù)據(jù)有多組,每組占一行,數(shù)據(jù)格式為YYYY/MM/DD組成,具體參見sampleinput,另外,可以向你確保所有的輸入數(shù)據(jù)是合法的。Output對于每組輸入數(shù)據(jù),輸出一行,表示該日期是該年的第幾天。SampleInput1985/1/202006/3/12SampleOutput2071AuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>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;elsed=d;}elseif<g=0>d=d+1;elsed=d;printf<"%d\n",d>;}}2006求奇數(shù)的乘積ProblemDescription給你n個整數(shù),求他們中所有奇數(shù)的乘積。Input輸入數(shù)據(jù)包含多個測試實例,每個測試實例占一行,每行的第一個數(shù)為n,表示本組數(shù)據(jù)一共有n個,接著是n個整數(shù),你可以假設(shè)每組數(shù)據(jù)必定至少存在一個奇數(shù)。Output輸出每組數(shù)中的所有奇數(shù)的乘積,對于測試實例,輸出一行。SampleInput312342345SampleOutput315AuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>main<>{intn,s,i,a;while<scanf<"%d",&n>!=EOF>{s=1;for<i=0;i<n;i++>{scanf<"%d",&a>;if<a%2==1>s=s*a;else;}printf<"%d\n",s>;}}2007平方和與立方和ProblemDescription給定一段連續(xù)的整數(shù),求出他們中所有偶數(shù)的平方和以及所有奇數(shù)的立方和。Input輸入數(shù)據(jù)包含多組測試實例,每組測試實例包含一行,由兩個整數(shù)m和n組成。Output對于每組輸入數(shù)據(jù),輸出一行,應(yīng)包括兩個整數(shù)x和y,分別表示該段連續(xù)的整數(shù)中所有偶數(shù)的平方和以及所有奇數(shù)的立方和。

你可以認(rèn)為32位整數(shù)足以保存結(jié)果。SampleInput1325SampleOutput42820152AuthorlcySourceC語言程序設(shè)計練習(xí)〔一RecommendJGShining解答:#include<stdio.h>intmain<>{intsum1,sum2,n,i,m,t;while<scanf<"%d%d",&m,&n>!=EOF>{sum1=sum2=0;if<m>n>{t=m;m=n;n=t;}for<i=m;i<=n;i++>{if<i%2==0>sum1+=<i*i>;elsesum2+=<i*i*i>;}printf<"%d%d\n",sum1,sum2>;}return0;}2008數(shù)值統(tǒng)計ProblemDescription統(tǒng)計給定的n個數(shù)中,負(fù)數(shù)、零和正數(shù)的個數(shù)。Input輸入數(shù)據(jù)有多組,每組占一行,每行的第一個數(shù)是整數(shù)n〔n<100,表示需要統(tǒng)計的數(shù)值的個數(shù),然后是n個實數(shù);如果n=0,則表示輸入結(jié)束,該行不做處理。Output對于每組輸入數(shù)據(jù),輸出一行a,b和c,分別表示給定的數(shù)據(jù)中負(fù)數(shù)、零和正數(shù)的個數(shù)。SampleInput60123-10512340.50SampleOutput123005AuthorlcySourceC語言程序設(shè)計練習(xí)〔二RecommendJGShining解答:#include<stdio.h>intmain<>{intn,i,b1,b2,b3;doublea[101];while<scanf<"%d",&n>!=EOF&&n!=0>{for<i=0;i<n;i++>scanf<"%lf",&a[i]>;b1=b2=b3=0;for<i=0;i<n;i++>{if<a[i]<0>b1++;elseif<a[i]==0>b2++;elseb3++;}printf<"%d%d%d\n",b1,b2,b3>;}}2009求數(shù)列的和ProblemDescription數(shù)列的定義如下:

數(shù)列的第一項為n,以后各項為前一項的平方根,求數(shù)列的前m項的和。Input輸入數(shù)據(jù)有多組,每組占一行,由兩個整數(shù)n〔n<10000和m<m<1000>組成,n和m的含義如前所述。Output對于每組輸入數(shù)據(jù),輸出該數(shù)列的和,每個測試實例占一行,要求精度保留2位小數(shù)。SampleInput81422SampleOutput94.733.41AuthorlcySourceC語言程序設(shè)計練習(xí)〔二RecommendJGShining解答:#include<stdio.h>#include<math.h>main<>{doublen,m,s,w,i;while<scanf<"%lf%lf",&n,&m>!=EOF>{s=n;for<i=1;i<m;i++>{n=sqrt<n>;s=s+n;}printf<"%.2lf\n",s>;}}2010水仙花數(shù)ProblemDescription春天是鮮花的季節(jié),水仙花就是其中最迷人的代表,數(shù)學(xué)上有個水仙花數(shù),他是這樣定義的:

"水仙花數(shù)"是指一個三位數(shù),它的各位數(shù)字的立方和等于其本身,比如:153=1^3+5^3+3^3。

現(xiàn)在要求輸出所有在m和n圍的水仙花數(shù)。Input輸入數(shù)據(jù)有多組,每組占一行,包括兩個整數(shù)m和n〔100<=m<=n<=999。Output對于每個測試實例,要求輸出所有在給定圍的水仙花數(shù),就是說,輸出的水仙花數(shù)必須大于等于m,并且小于等于n,如果有多個,則要求從小到大排列在一行輸出,之間用一個空格隔開;

如果給定的圍不存在水仙花數(shù),則輸出no;

每個測試實例的輸出占一行。SampleInput100120300380SampleOutputno370371AuthorlcySourceC語言程序設(shè)計練習(xí)〔二RecommendJGShining解答:#include<stdio.h>main<>{intm,n,i,w,a,b,c,j,s,d;while<scanf<"%d%d",&n,&m>!=EOF>{d=0;j=1;if<m>n>{w=m;m=n;n=w;}else;for<i=m;i<=n;i++>{a=i/100;b=i/10%10;c=i%10;s=a*a*a+b*b*b+c*c*c;if<i==s>{if<d!=0>printf<"">;printf<"%d",i>;d=d+1;j=j+1;}}if<j==1>printf<"no\n">;elseprintf<"\n">;}}2011多項式求和ProblemDescription多項式的描述如下:

1-1/2+1/3-1/4+1/5-1/6+...

現(xiàn)在請你求出該多項式的前n項的和。Input輸入數(shù)據(jù)由2行組成,首先是一個正整數(shù)m〔m<100,表示測試實例的個數(shù),第二行包含m個正整數(shù),對于每一個整數(shù)<不妨設(shè)為n,n<1000,求該多項式的前n項的和。Output對于每個測試實例n,要求輸出多項式前n項的和。每個測試實例的輸出占一行,結(jié)果保留2位小數(shù)。SampleInput212SampleOutput1.000.50AuthorlcySourceC語言程序設(shè)計練習(xí)〔二RecommendJGShining解答:#include<stdio.h>#include<math.h>main<>{doublem,n,i,s,j,k,a;while<scanf<"%lf",&m>!=EOF>{for<i=0;i<m;i++>{s=0;scanf<"%lf",&n>;for<j=1;j<=n;j++>s=s+1/j*pow<-1,j+1>;printf<"%.2lf\n",s>;}}}2012素數(shù)判定ProblemDescription對于表達(dá)式n^2+n+41,當(dāng)n在〔x,y圍取整數(shù)值時〔包括x,y<-39<=x<y<=50>,判定該表達(dá)式的值是否都為素數(shù)。Input輸入數(shù)據(jù)有多組,每組占一行,由兩個整數(shù)x,y組成,當(dāng)x=0,y=0時,表示輸入結(jié)束,該行不做處理。Output對于每個給定圍的取值,如果表達(dá)式的值都為素數(shù),則輸出"OK",否則請輸出"Sorry",每組輸出占一行。SampleInput0100SampleOutputOKAuthorlcySourceC語言程序設(shè)計練習(xí)〔二RecommendJGShining解答:#include<stdio.h>main<>{intx,y,i,j,s,k,w,d;while<scanf<"%d%d",&x,&y>==2&&<x!=0||y!=0>>{w=0;for<i=x;i<=y;i++>{k=i*i+i+41;for<j=2;j<k;j++>{d=k%j;if<d==0>w++;}}if<w==0>printf<"OK\n">;elseprintf<"Sorry\n">;}}2014青年歌手大獎賽_評委會打分ProblemDescription青年歌手大獎賽中,評委會給參賽選手打分。選手得分規(guī)則為去掉一個最高分和一個最低分,然后計算平均得分,請編程輸出某選手的得分。Input輸入數(shù)據(jù)有多組,每組占一行,每行的第一個數(shù)是n<2<n<100>,表示評委的人數(shù),然后是n個評委的打分。Output對于每組輸入數(shù)據(jù),輸出選手的得分,結(jié)果保留2位小數(shù),每組輸出占一行。SampleInput39998974100999897SampleOutput98.0098.50AuthorlcySourceC語言程序設(shè)計練習(xí)〔三Recommendlcy解答:#include<stdio.h>intmain<>{intn,s,a[100],i,k,b;doublew;while<scanf<"%d",&n>!=EOF>{k=0;w=0;s=0;for<i=0;i<n;i++>{scanf<"%d",&a[i]>;k++;b=a[0];w=w+a[i];}for<i=0;i<k;i++>{if<a[i]>s>s=a[i];}for<i=1;i<k;i++>{if<b>a[i]>b=a[i];}w=<w-s-b>/<k-2>;printf<"%.2lf\n",w>;}}2015偶數(shù)求和ProblemDescription有一個長度為n<n<=100>的數(shù)列,該數(shù)列定義為從2開始的遞增有序偶數(shù),現(xiàn)在要求你按照順序每m個數(shù)求出一個平均值,如果最后不足m個,則以實際數(shù)量求平均值。編程輸出該平均值序列。Input輸入數(shù)據(jù)有多組,每組占一行,包含兩個正整數(shù)n和m,n和m的含義如上所述。Output對于每組輸入數(shù)據(jù),輸出一個平均值序列,每組輸出占一行。SampleInput3242SampleOutput3637AuthorlcySourceC語言程序設(shè)計練習(xí)〔三Recommendlcy解答:#include<stdio.h>main<>{intn,m,a,b,i,j,k,w,l,e,s,d,r;while<scanf<"%d%d",&n,&m>!=EOF>{s=0;e=0;l=0;if<n<=m>{for<i=0;i<n;i++>{s=s+2;e=e+s;k=e/n;}printf<"%d\n",k>;}else{w=n%m;r=0;for<i=1;i<=n-w;i++>{s=s+2;l=l+s;e=e+s;if<i%m==0>{k=e/m;e=0;if<r>printf<"">;printf<"%d",k>;r=r+1;}}s=0;if<w!=0>{for<j=0;j<n;j++>{s=s+2;e=e+s;}d=e-l;k=d/w;printf<"">;printf<"%d",k>;}printf<"\n">;}}}2016數(shù)據(jù)的交換輸出ProblemDescription輸入n<n<100>個數(shù),找出其中最小的數(shù),將它與最前面的數(shù)交換后輸出這些數(shù)。Input輸入數(shù)據(jù)有多組,每組占一行,每行的開始是一個整數(shù)n,表示這個測試實例的數(shù)值的個數(shù),跟著就是n個整數(shù)。n=0表示輸入的結(jié)束,不做處理。Output對于每組輸入數(shù)據(jù),輸出交換后的數(shù)列,每組輸出占一行。SampleInput421345543210SampleOutput123414325AuthorlcySourceC語言程序設(shè)計練習(xí)〔三Recommendlcy解答:#include<stdio.h>main<>{intn,a[100],i,j,k,s,w;while<scanf<"%d",&n>!=EOF&&n!=0>{j=0;for<i=0;i<n;i++>{scanf<"%d",&a[i]>;k=a[0];}for<i=0;i<n;i++>{if<k>a[i]>{k=a[i];j=i;}}w=a[0];a[0]=k;a[j]=w;for<i=0;i<n;i++>{printf<"%d",a[i]>;if<n-i!=1>printf<"">;}printf<"\n">;}}2017字符串統(tǒng)計ProblemDescription對于給定的一個字符串,統(tǒng)計其中數(shù)字字符出現(xiàn)的次數(shù)。Input輸入數(shù)據(jù)有多行,第一行是一個整數(shù)n,表示測試實例的個數(shù),后面跟著n行,每行包括一個由字母和數(shù)字組成的字符串。Output對于每個測試實例,輸出該串中數(shù)值的個數(shù),每個輸出占一行。SampleInput2asdfasdf123123asdfasdfasdf111111111asdfasdfasdfSampleOutput69Authorlcy解答:#include<stdio.h>main<>{intn,i,j,a;chars[1000];while<scanf<"%d",&n>!=EOF>{getchar<>;for<i=0;i<n;i++>{gets<s>;a=0;for<j=0;s[j]!='\0';j++>{if<<s[j]<='9'>&&<s[j]>='0'>>a=a+1;}printf<"%d\n",a>;}}}2019數(shù)列有序!ProblemDescription有n<n<=100>個整數(shù),已經(jīng)按照從小到大順序排列好,現(xiàn)在另外給一個整數(shù)x,請將該數(shù)插入到序列中,并使新的序列仍然有序。Input輸入數(shù)據(jù)包含多個測試實例,每組數(shù)據(jù)由兩行組成,第一行是n和m,第二行是已經(jīng)有序的n個數(shù)的數(shù)列。n和m同時為0標(biāo)示輸入數(shù)據(jù)的結(jié)束,本行不做處理。Output對于每個測試實例,輸出插入新的元素后的數(shù)列。SampleInput3312400SampleOutput1234AuthorlcySourceC語言程序設(shè)計練習(xí)〔三Recommendlcy解答:#include<stdio.h>main<>{intn,m,a[100],b[100],i,j,k,s,w,d;scanf<"%d%d",&n,&m>;while<!<n==0&&m==0>>{w=0;for<i=0;i<n;i++>scanf<"%d",&a[i]>;s=a[0];if<m<s>{printf<"%d",m>;for<j=0;j<n;j++>{printf<"">;printf<"%d",a[j]>;}}else{for<j=0;j<n;j++>{if<m>a[j]>w=w+1;}for<j=0;j<w;j++>{printf<"%d",a[j]>;printf<"">;}printf<"%d",m>;for<j=w;j<n;j++>{printf<"">;printf<"%d",a[j]>;}}printf<"\n">;scanf<"%d%d",&n,&m>;}}2020絕對值排序ProblemDescription輸入n<n<=100>個整數(shù),按照絕對值從大到小排序后輸出。題目保證對于每一個測試實例,所有的數(shù)的絕對值都不相等。Input輸入數(shù)據(jù)有多組,每組占一行,每行的第一個數(shù)字為n,接著是n個整數(shù),n=0表示輸入數(shù)據(jù)的結(jié)束,不做處理。Output對于每個測試實例,輸出排序后的結(jié)果,兩個數(shù)之間用一個空格隔開。每個測試實例占一行。SampleInput33-424012-30SampleOutput-432-3210AuthorlcySourceC語言程序設(shè)計練習(xí)〔三Recommendlcy解答:#include<stdio.h>main<>{intn,m,a[100],b[100],c,d,e,f,i,j,k;while<scanf<"%d",&n>!=EOF&&n!=0>{for<i=0;i<n;i++>scanf<"%d",&a[i]>;f=0;for<j=0;j<n;j++>{c=0;for<i=0;i<n;i++>{if<a[i]<0>m=-a[i];elsem=a[i];if<c<=m>{c=m;b[j]=a[i];k=i;}}a[k]=0;if<f>printf<"">;printf<"%d",b[j]>;f=f+1;}printf<"\n">;}}2021發(fā)工資咯:ProblemDescription作為杭電的老師,最盼望的日子就是每月的8號了,因為這一天是發(fā)工資的日子,養(yǎng)家糊口就靠它了,呵呵

但是對于學(xué)校財務(wù)處的工作人員來說,這一天則是很忙碌的一天,財務(wù)處的小胡老師最近就在考慮一個問題:如果每個老師的工資額都知道,最少需要準(zhǔn)備多少人民幣,才能在給每位老師發(fā)工資的時候都不用老師找零呢?

這里假設(shè)老師的工資都是正整數(shù),單位元,人民幣一共有100元、50元、10元、5元、2元和1元六種。Input輸入數(shù)據(jù)包含多個測試實例,每個測試實例的第一行是一個整數(shù)n〔n<100,表示老師的人數(shù),然后是n個老師的工資。

n=0表示輸入的結(jié)束,不做處理。Output對于每個測試實例輸出一個整數(shù)x,表示至少需要準(zhǔn)備的人民幣數(shù)。每個輸出占一行。SampleInput31230SampleOutput4AuthorlcySourceC語言程序設(shè)計練習(xí)〔四Recommendlcy解答:#include<stdio.h>main<>{intn,m,a,b,c,d,e,f,i,j,k;while<scanf<"%d",&n>!=EOF&&n!=0>{k=0;for<i=0;i<n;i++>{scanf<"%d",&m

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論