fork download
  1. #include <iostream>
  2. using namespace std;
  3. bool isIcecreamSandwich(string s){
  4. string n;
  5. for(int i = 0; i <= s.length() / 2; ++i)
  6. if(s[i] != s[s.length() - i - 1] || (n = !i || s[i] != n[n.length() - 1] ? n + s[i] : n).length() > 2)
  7. return false;
  8. return n.length() == 2;
  9. }
  10. int main(){
  11. string s;
  12. getline(cin, s), cout << boolalpha << isIcecreamSandwich(s);
  13. }
Success #stdin #stdout 0s 4532KB
stdin
AAA*****AAA
stdout
true