fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool is_palindrome(const std::string &str) {
  5. bool result = true;
  6.  
  7. int i = 0;
  8. int j = str.size() - 1;
  9.  
  10. while(i < j) {
  11. while(str[i] == ' ' && i < j) {
  12. ++i;
  13. }
  14.  
  15. while(str[j] == ' ' && i < j) {
  16. --j;
  17. }
  18.  
  19. if (toupper(str[i]) != toupper(str[j])) {
  20. result = false;
  21. break;
  22. }
  23.  
  24. ++i;
  25. --j;
  26. }
  27.  
  28. return result;
  29. }
  30.  
  31. int main() {
  32. string str;
  33.  
  34. while(getline (cin, str)) {
  35. cout << (is_palindrome(str) ? "TAK": "NIE") << "\n";
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 3472KB
stdin
test
kajak

a
Kajak
Ka ja   k
 kaja k
stdout
NIE
TAK
TAK
TAK
TAK
TAK
TAK