Advertisement
dmkozyrev

419.cpp

May 6th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int is_palindrome(const string & s, int & i, int & j) {
  8.     for (i = 0, j = (int)(s.size()-1); i < j; ++i, --j)
  9.         if (s[i] != s[j])
  10.             return i;
  11.     return (j = (int)s.size(), i = -1);
  12. }
  13.  
  14. int main() {
  15.     int len = 0;
  16.     char c, buf[100100];
  17.     while (scanf("%c", &c) != EOF)
  18.         if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z')
  19.             buf[len++] = (c <= 'Z' ? c+'a'-'A':c);
  20.     buf[len] = '\0';
  21.    
  22.     string s[4];
  23.     s[0] = buf;
  24.    
  25.     int i, j;
  26.     if (is_palindrome(s[0], i, j) == -1) {
  27.         printf("YES\n%s", s[0].c_str());
  28.         return 0;
  29.     }
  30.    
  31.     s[1] = s[0].substr(0, i) + s[0].substr(i+1);
  32.     s[2] = s[0].substr(0, j) + s[0].substr(j+1);
  33.     s[3] = s[0].substr(0, i) + s[0][j] + s[0].substr(i+1);
  34.    
  35.     for (int k = 1; k < 4; ++k)
  36.         if (is_palindrome(s[k], i, j) == -1) {
  37.             printf("YES\n%s", s[k].c_str());
  38.             return 0;
  39.         }
  40.        
  41.     printf("NO");
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement