1. 程式人生 > >EOJ3650 轉機折扣(26進位制,字串)

EOJ3650 轉機折扣(26進位制,字串)

題面

看成26進位制,把較小的那個字串加1

strcmp(s1,s2)s1和s2有大小時,不一定都是返回1或者-1.。。。。這個地方wa了好幾次沒有發現

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char s1[100010],s2[100010];
 4 void print(char s[])
 5 {
 6     s[strlen(s)-1]+=1;
 7     for(int i=strlen(s)-1; i>=0; i--)
 8     {
 9 //        if(s[i]=='Z')
10 // { 11 // s[i]='A'; 12 // }else 13 // { 14 // s[i]++;break; 15 // } 16 int temp=0; 17 if(s[i]>'Z')temp=s[i]-'Z'; 18 if(temp>0) 19 { 20 s[i]='A'+temp-1; 21 s[i-1]+=1; 22 } 23 }
24 printf("%s\n",s); 25 } 26 int main() 27 { 28 while(~scanf("%s %s",s1,s2)) 29 { 30 if(strcmp(s1,s2)>0) 31 { 32 print(s2); 33 } 34 else 35 { 36 print(s1); 37 } 38 memset(s1,'\0',sizeof(s1)); 39
memset(s2,'\0',sizeof(s2)); 40 } 41 return 0; 42 }
View Code