杭电oj2081、2091、1004、2057
2081 手机短号
1 #include<stdio.h> 2 #include<string.h> 3 4 5 int main(){ 6 int i,n; 7 char s[20]; 8 while(scanf("%d",&n)!=EOF){ 9 getchar(); 10 while(n--){ 11 gets(s); 12 printf("6"); 13 for(i=6;i<11;i++){ 14 if(i==10){printf("%c\n",s[i]);} 15 else{printf("%c",s[i]);} 16 } 17 } 18 } 19 }
2091 空心三角形
1 #include<stdio.h> 2 #include<string.h> 3 4 5 int main(){ 6 char a; 7 int n,i,j,flag=0; 8 while((a=getchar())!='@'){ 9 scanf("%d%*c",&n); 10 if(flag!=0){printf("\n");} 11 flag++; 12 for(i=0;i<n;i++){ 13 if(i==0){ 14 printf("%*c\n",n,a); 15 continue; 16 } 17 if(i==n-1){ 18 for(j=0;j<2*n-1;j++){ 19 printf("%c",a); 20 } 21 printf("\n"); 22 break; 23 } 24 printf("%*c",n-i,a); 25 printf("%*c\n",2*i,a); 26 } 27 } 28 29 }
1004 Let the Balloon Rise
1 #include<stdio.h> 2 #include<string.h> 3 4 5 int main(){ 6 char s[1001][20]; 7 int n,i,j,max,flag,o[1001]; 8 while(scanf("%d",&n)!=EOF){ 9 getchar(); 10 if(n==0){break;} 11 for(i=0;i<n;i++){ 12 gets(s[i]); 13 } 14 for(i=0;i<n;i++){ 15 o[i]=0; 16 for(j=0;j<n;j++){ 17 if(strcmp(s[i],s[j])==0){o[i]++;} 18 } 19 } 20 max = o[0]; 21 flag = 0; 22 for(i=0;i<n;i++){ 23 if(o[i]>max){ 24 max = o[i]; 25 flag = i; 26 } 27 } 28 printf("%s\n",s[flag]); 29 } 30 }
2057 A + B Again
1 #include<stdio.h> 2 3 int main(){ 4 _int64 a,b; 5 while(scanf("%I64X %I64X",&a,&b)!=EOF){ 6 if(a+b<0){printf("-%I64X\n",-a-b);} 7 else{printf("%I64X\n",a+b);} 8 } 9 }