Advertisement
immuntasir

a

Feb 24th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <cstring>
  2. #include <cstdio>
  3.  
  4. char a[100];
  5. char b[100];
  6. char c[100];
  7.  
  8. int main() {
  9.     scanf("%s %s", a,b);
  10.     int len = strlen(a);
  11.     int i;
  12.     int x,y;
  13.     strcpy(c,b);
  14.  
  15.     for(i=len-1;i>=0;i--) {
  16.         if (c[i] != 'a') {
  17.             c[i] -=1;
  18.             break;
  19.         }
  20.     }
  21.     x = strcmp(c,a);
  22.     y = strcmp(c,b);
  23.  
  24.     if (x>0 && y<0) printf("%s\n",c);
  25.     else {
  26.         strcpy(c,a);
  27.         for(i=len-1;i>=0;i--) {
  28.             if (c[i] != 'z') {
  29.                 c[i] +=1;
  30.                 break;
  31.             }
  32.         }
  33.         x = strcmp(c,a);
  34.         y = strcmp(c,b);
  35.         if (x>0 && y<0) printf("%s\n",c);
  36.         else printf("No such string\n");
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement