//#define _CRT_SECURE_NO_WARNINGS #include <iostream> //#include <fstream> using namespace std; char c; unsigned long long n,p, l1, hp, ha1, hb1, th1=10000000000000079; //fstream plik; int main() { ios_base::sync_with_stdio(0); //plik.open("palindrom.txt"); scanf("%ulld", &n); //plik >> n; hp = 1; p = 29; ha1 = 0; hb1 = 0; scanf("%c", &c); while (scanf("%c", &c) /*plik >> c*/) { if ((int)c == 10)break; l1=(int)c-96; ha1 += hp * c; hb1 *= p; hb1 += c; hp *= p; hp %= th1; ha1 %= th1; hb1 %= th1; } if (ha1 == hb1)printf("TAK\n"); else printf("NIE\n"); //plik.close(); //system("PAUSE"); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | //#define _CRT_SECURE_NO_WARNINGS #include <iostream> //#include <fstream> using namespace std; char c; unsigned long long n,p, l1, hp, ha1, hb1, th1=10000000000000079; //fstream plik; int main() { ios_base::sync_with_stdio(0); //plik.open("palindrom.txt"); scanf("%ulld", &n); //plik >> n; hp = 1; p = 29; ha1 = 0; hb1 = 0; scanf("%c", &c); while (scanf("%c", &c) /*plik >> c*/) { if ((int)c == 10)break; l1=(int)c-96; ha1 += hp * c; hb1 *= p; hb1 += c; hp *= p; hp %= th1; ha1 %= th1; hb1 %= th1; } if (ha1 == hb1)printf("TAK\n"); else printf("NIE\n"); //plik.close(); //system("PAUSE"); } |