fork(2) download
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. unsigned short tTest = 0;
  7. cin >> tTest;
  8. if(tTest > 10 || tTest < 1)
  9. return 0;
  10. unsigned long charlen = 0;
  11. bool isPalindrome = true;
  12. while(tTest)
  13. {
  14. char *nSlowo;
  15. cin >> charlen;
  16. if(charlen > 1000000 || charlen < 1)
  17. break;
  18. nSlowo = new char[charlen];
  19. cin >> nSlowo;
  20. for(int i = 0; i < charlen; i++)
  21. {
  22. // warunek, gdy slowo ma tylko 1 litere
  23. if(charlen == 1){isPalindrome = false; break;}
  24. else if(nSlowo[i] == nSlowo[i+1]){isPalindrome = true; break;}
  25. else if(i < charlen-3)
  26. {
  27. if(nSlowo[i] != nSlowo[i+1] && nSlowo[i] == nSlowo[i+2])
  28. { isPalindrome = true; break;}
  29. }
  30. else
  31. {
  32. for(int j = 0; j < charlen; j++)
  33. {
  34. if(nSlowo[j] != nSlowo[(charlen-1)-j])
  35. {isPalindrome = false; break;}
  36. }
  37. if(isPalindrome)
  38. {isPalindrome = true; break;}
  39. }
  40. }
  41. if(isPalindrome)cout << "TAK\n";
  42. else cout << "NIE\n";
  43. delete [] nSlowo;
  44. tTest--;
  45. }
  46. cin.sync();
  47. cin.get();
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
Standard output is empty