string s_to_p(string s); |
Given a string s, s_to_p() should return a palindrome that is produced by changing the minimum possible number of characters in s. Changing a character means replacing it with any single character at the same position. You are not allowed to remove or add any characters. If there are multiple answers, return the one that comes first alphabetically.
Constraints:
#include <iostream> using namespace std; main() { string s; while (cin >> s) cout << s_to_p(s) << endl; } |
Here are some examples:
UNIX> cat -n input.txt 1 fred 2 dontonio 3 babydaisy 4 abba 5 abacab 6 xxyy 7 yyxx 8 xxy 9 madamimadam UNIX> a.out < input.txt | cat -n 1 deed 2 dinoonid 3 babadabab 4 abba 5 aaaaaa 6 xxxx 7 xxxx 8 xxx 9 madamimadam UNIX>