資源描述:
《杭電acm答案無敵版.doc》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、選修課考試作業(yè)2012素數(shù)判定332014青年歌手大獎賽_評委會打分342017字符串統(tǒng)計402019數(shù)列有序!412020絕對值排序432033人見人愛A+B462039三角形482040親和數(shù)49姓名:春杰級:電商141001SumProblemProblemDescriptionHey,welcometoHDOJ(HangzhouDianziUniversityOnlineJudge).Inthisproblem,yourtaskistocalculateSUM(n)=1+2+3+...+n.?Inpu
2、tTheinputwillconsistofaseriesofintegersn,oneintegerperline.?OutputForeachcase,outputSUM(n)inoneline,followedbyablankline.Youmayassumetheresultwillbeintherangeof32-bitsignedinteger.?SampleInput1100?SampleOutput15050?AuthorDOOMIII解答:#includemain(){in
3、tn,i,sum;sum=0;while((scanf("%d",&n)!=-1)){sum=0;for(i=0;i<=n;i++)sum+=i;printf("%d",sum);}}1089A+BforInput-OutputPractice(I)ProblemDescriptionYourtaskistoCalculatea+b.Tooeasy?!Ofcourse!Ispeciallydesignedtheproblemforacmbeginners.Youmusthavefoundthatsom
4、eproblemshavethesametitleswiththisone,yes,alltheseproblemsweredesignedforthesameaim.?InputTheinputwillconsistofaseriesofpairsofintegersaandb,separatedbyaspace,onepairofintegersperline.?OutputForeachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneli
5、ne,andwithonelineofoutputforeachlineininput.?SampleInput151020?SampleOutput630?Authorlcy?RecommendJGShining解答:#includemain(){inta,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d",a+b);}1090A+BforInput-OutputPractice(II)ProblemDescriptionYourtaskistoC
6、alculatea+b.?InputInputcontainsanintegerNinthefirstline,andthenNlinesfollow.Eachlineconsistsofapairofintegersaandb,separatedbyaspace,onepairofintegersperline.?OutputForeachpairofinputintegersaandbyoushouldoutputthesumofaandbinoneline,andwithonelineofoutputf
7、oreachlineininput.?SampleInput2151020?SampleOutput630?Authorlcy?RecommendJGShining解答:#include#defineM1000voidmain(){inta,b,n,j[M],i;//printf("pleaseinputn:");scanf("%d",&n);for(i=0;i8、hile(i