### Problem
John and Brus are studying string theory at the university. Brus likes palindromes very much. A palindrome is a word that reads the same forward and backward. John would like to surprise Brus by taking a String s, and appending 0 or more characters to the end of s to obtain a palindrome. He wants that palindrome to be as short as possible. Return the shortest possible length of a palindrome that John can generate.
### Answer
#include <vector>
using namespace std;
class ThePalindrome {
public:
int find(string s) {
for(int i = s.size(); ; i++){
bool flag = true;
for(int j = 0; j < s.size(); j++) {
if((i - j - 1) < s.size() && s[j] != s[i - j - 1] ){
flag = false;
break;
}
}
if(flag) return i;
}
}
}
最初と最後の文字の比較を左から順にやっていき、一致しなければ「?」文字を追加していく。
実装方法と問題のイメージ両方必要ですな。