Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <string>
- using namespace std;
- int is_palindrome(const string & s, int & i, int & j) {
- for (i = 0, j = (int)(s.size()-1); i < j; ++i, --j)
- if (s[i] != s[j])
- return i;
- return (j = (int)s.size(), i = -1);
- }
- int main() {
- int len = 0;
- char c, buf[100100];
- while (scanf("%c", &c) != EOF)
- if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z')
- buf[len++] = (c <= 'Z' ? c+'a'-'A':c);
- buf[len] = '\0';
- string s[4];
- s[0] = buf;
- int i, j;
- if (is_palindrome(s[0], i, j) == -1) {
- printf("YES\n%s", s[0].c_str());
- return 0;
- }
- s[1] = s[0].substr(0, i) + s[0].substr(i+1);
- s[2] = s[0].substr(0, j) + s[0].substr(j+1);
- s[3] = s[0].substr(0, i) + s[0][j] + s[0].substr(i+1);
- for (int k = 1; k < 4; ++k)
- if (is_palindrome(s[k], i, j) == -1) {
- printf("YES\n%s", s[k].c_str());
- return 0;
- }
- printf("NO");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement