杭电2000~A+BforInput-OutputPractice(VIII)TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):5573AcceptedSubmission(s):2058ProblemDescriptionYourtaskistocalculatethesumofsomeintegers.InputInputcontainsanintegerNinthefirstline,andthenNlinesfollow.EachlinestartswithaintegerM,andthenMintegersfollowinthesameline.OutputForeachgroupofinputintegersyoushouldoutputtheirsuminoneline,andyoumustnotethatthereisablanklinebetweenoutputs.SampleInput3412345123453123SampleOutput10156正确代码:#includeiostreamusingnamespacestd;intmain(){intm,n,i,j,s,k;cinn;intc[1000];for(i=0;in;i++){cinm;s=0;for(j=1;j=m;j++){cink;s+=k;}if(i==n-1){coutsendl;}else{coutsendlendl;}}return0;}A+BComingTimeLimit:1000/1000MS(Java/Others)MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):902AcceptedSubmission(s):456ProblemDescriptionManyclassmatessaidtomethatA+Bismustneeds.Ifyoucan’tACthisproblem,youwouldinvitemefornightmeal.^_^InputInputmaycontainmultipletestcases.EachcasecontainsAandBinoneline.A,Barehexadecimalnumber.InputterminatesbyEOF.OutputOutputA+Bindecimalnumberinoneline.SampleInput19ABabSampleOutput102121正确代码:#includeiostreamusingnamespacestd;intmain(){intm,n,s;while(scanf(%x%x,&m,&n)!=EOF)//以十六进制输入{s=m+n;printf(%d\n,s);//以十进制输出,与上面}return0;}此题的输入输出没有用cin和cout,看到很多人说scanf和printf比较常用2001ASCII码排序TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):32853AcceptedSubmission(s):13545ProblemDescription输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。Input输入数据有多组,每组占一行,有三个字符组成,之间无空格。Output对于每组输入数据,输出一行,字符中间用一个空格分开。SampleInputqweasdzxcSampleOutputeqwadscxz正确代码:#includeiostreamusingnamespacestd;intmain(){charch[1000];while(cinch){if(ch[0]ch[1])swap(ch[0],ch[1]);if(ch[0]ch[2])swap(ch[0],ch[2]);if(ch[1]ch[2])swap(ch[1],ch[2]);coutch[0]ch[1]ch[2]endl;}return0;}2002计算球体积TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):33845AcceptedSubmission(s):13142ProblemDescription根据输入的半径值,计算球的体积。Input输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。Output输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。SampleInput11.5SampleOutput4.18914.137Hint#definePI3.1415927正确代码:#includeiostream#includecmath#includeiomanip#definePI3.1415927usingnamespacestd;intmain(){doubler,v;while(cinr){v=4*PI*r*r*r/3;coutsetiosflags(ios::fixed);coutsetprecision(3)vendl;}return0;}2005第几天?TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):27335AcceptedSubmission(s):10557ProblemDescription给定一个日期,输出这个日期是该年的第几天。Input输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sampleinput,另外,可以向你确保所有的输入数据是合法的。Output对于每组输入数据,输出一行,表示该日期是该年的第几天。SampleInput1985/1/202006/3/12SampleOutput2071正确代码:#includestdio.hintmain(){inty,m,d,i=0,s;while(scanf(%d/%d/%d,&y,&m,&d)!=EOF){intc[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};if(y%4!=0||(y%100==0&&y%400!=0)){//如果是平年红色部分为判断为平年的模板代码c[2]=28;}s=0;for(i=0;im;i++){s=s+c[i];}s=s+d;printf(%d\n,s);}return0;}2006求奇数的乘积TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):17640AcceptedSubmission(s):11525ProblemDescription给你n个整数,求他们中所有奇数的乘积。Input输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。Output输出每组数中的所有奇数的乘积,对于测试实例,输出一行。SampleInput312342345SampleOutput315正确代码:#includeiostreamusingnamespacestd;intmain(){intn,m,i,s;//intj;while(cinn){s=1;for(i=0;in;i++){cinm;//j=0;if(m%2!=0)//{s=s*m;//j++;//}}//if(j==0)//s=0;coutsendl;}return0;}注意:题目中已经说”你可以假设每组数据必定至少存在一个奇数。”所以就没有必要再列出没有一个奇数的情况!2007平方和与立方和TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):37671AcceptedSubmission(s):10965ProblemDescription给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。Input输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。Output对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。你可以认为32位整数足以保存结果。SampleInput1325SampleOutput42820152正确代码:#includeiostreamusingnamespacestd;intmain(){intn,m,i,temp;ints1,s2;while(cinnm){s1=0,s2=0;if(nm){temp=n;n=m;m=temp;}for(i=n;i=m;i++){if(i%2==0)s2+=i*i;elses1+=i*i*i;}couts2s1endl;}return0;}题解:输入的两个区间大小不一定2008数值统计TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):20378AcceptedSubmission(s):10783ProblemDescription统计给定的n个数中,负数、零和正数的个数。Input输入数据有多组,每组占一行,每行的第一个数是整数n(n100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。Output对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。SampleInput60123-10512340.50SampleOutput123005正确代码:#includeiostreamusingnamespacestd;intmain(){intn;doublem;while(cinn){if(n==0)break;inti,a=0,b=0,c=0;for(i=0;in;i++){cinm;if(m0)a++;if(m==0)b++;if(m0)c++;}coutabcendl;}return0;}注意:题目中虽然没说输出格式,但是abc之间有空格输出才行2009求数列的和TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):16873AcceptedSubmission(s):10295ProblemDescription数列的定义如下:数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。Input输入数据有多组,每组占一行,由两个整数n(n10000)和m(m1000)组成,n和m的含义如前所述。Output对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。SampleInput81422SampleOutput94.733.41正确代码:#includeiostream#includeiomanip#includ