资源描述:
《ACM入门十题(杭电oj).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ACM入门(杭电oj)Hdu1000#include#includeintmain(){inta,b;while(scanf("%d%d",&a,&b)!=EOF){printf("%d",a+b);}}Hdu1001#include#includeintmain(){intn;while(scanf("%d",&n)!=EOF){printf("%I64d",(__int64)(1+n)*n/2);}}Hdu1002#include#
2、include#includecharstr1[1005],str2[10005];intmain(){intca,count=0;scanf("%d",&ca);while(ca--){scanf("%s%s",str1,str2);inta[1005],i,j;memset(a,0,sizeof(a));for(i=strlen(str1)-1,j=0;i>=0;i--,j++)a[j]=str1[i]-'0';for(i=strlen(str2)-1,j=0;i>=0;i--,j++){a[j]
3、=a[j]+str2[i]-'0';a[j+1]=a[j+1]+a[j]/10;a[j]=a[j]%10;}count++;printf("Case%d:",count);printf("%s+%s=",str1,str2);intflag=0;for(i=1004;i>=0;i--)if(flag
4、
5、a[i]){printf("%d",a[i]);flag=1;}printf("");if(ca!=0)printf("");}}Hdu1003#include#includeinta[100
6、005],sum[100005];intmain(){intca,count=0;scanf("%d",&ca);while(ca--){intn,i;scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d",&a[i]);sum[1]=a[1];intr=1,max=a[1];for(i=2;i<=n;i++){if(sum[i-1]>0){sum[i]=sum[i-1]+a[i];if(sum[i]>max){max=sum[i];r=i;}}else{sum[i]=a[i];if(sum[i]>max){m
7、ax=sum[i];r=i;}}}count++;for(i=r-1;i>0;i--)if(sum[i]<0)break;printf("Case%d:",count);printf("%d%d%d",max,i+1,r);if(ca!=0)printf("");}}Hdu1004#include#includeusingnamespacestd;structpoint{charc[50];}p[1005];intcmp(pointp1,pointp2){returnstrcmp(p1.
8、c,p2.c)<0;}intmain(){intn,i;while(scanf("%d",&n)!=EOF&&n){for(i=0;ict){strcpy(res,p[i].c);ct=num;}}printf("%s",re
9、s);}}Hdu1005#include#include#includeints[10][10],c[1000];intmain(){c[1]=1;c[2]=1;inta,b,n;while(scanf("%d%d%d",&a,&b,&n)!=EOF){if(a==0&&b==0&&n==0)break;memset(s,0,sizeof(s));s[1][1]=1;inti;for(i=3;;i++){c[i]=(a*c[i-1]+b*c[i-2])%7;if(s[c[i-1]][
10、c[i]]!=0)break;s[c[i-1]][c[i]]=i-1;}/*for(intj=1;j<=i;j++)printf("%d",c[j]);*/intm=s[c[i-