fork(1) download
  1. #include <bits/stdc++.h>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. bool ispalindrome(string s)
  7. {
  8. int i=0;
  9. int j=s.size()-1;
  10. while(i<j)
  11. {
  12. if (s[i]==' ')i++;
  13. if (s[j]==' ')j--;
  14. if(tolower(s[i])!=tolower(s[j]))return false;
  15. i++;
  16. j--;
  17. }
  18. return true;
  19. }
  20.  
  21. int main()
  22. {
  23. //freopen("palindrom.in", "r", stdin);
  24. //freopen("palindrom.out", "w", stdout);
  25. string s;
  26. string phraze;
  27. float num;
  28. int temp=0;
  29. bool found_palindrome = false;
  30. while(getline(cin,s))
  31. {
  32. int index=s.find_first_of("!.?");
  33. //cout<<index<<'\n';
  34. phraze=(s.substr(temp,index));
  35. //cout<<phraze<<'\n';
  36. if(ispalindrome(phraze) && phraze.size()-1 > 1)
  37. {
  38. found_palindrome = true;
  39. cout<<phraze<<'\n';
  40. }
  41. temp=index+1;
  42. }
  43. if (!found_palindrome) cout << "-1" << '\n';
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5476KB
stdin
po t o p.
po t o p .
stdout
po t o p