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

猜你喜欢

转载自www.cnblogs.com/fqfzs/p/9974211.html