#include<iostream> #include <math.h> using namespace std; unsigned long long getHash(char a) { //12-digits prime % 2^32 return (a * 655373525717ULL) % 4294967296ULL; } unsigned long long obetnij(unsigned long long liczba) { return liczba % 10000000000000000000ULL; } unsigned long long startHash = 0; unsigned long long endHash = 0; unsigned long long sumaHashy = 0; int main() { std::ios_base::sync_with_stdio(false); char a; do { a = getchar(); } while (isspace(a) || isdigit(a)); unsigned long long i = 1; do { if (isspace(a)) { break; } unsigned long long tenHash = getHash(a); startHash += tenHash * i; sumaHashy += tenHash; endHash += sumaHashy; startHash = obetnij(startHash); endHash = obetnij(endHash); i++; } while ((a = getchar()) != EOF); if (startHash == endHash) { cout << "TAK" <<endl; } else { cout << "NIE" << endl; } return 0; }
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include<iostream> #include <math.h> using namespace std; unsigned long long getHash(char a) { //12-digits prime % 2^32 return (a * 655373525717ULL) % 4294967296ULL; } unsigned long long obetnij(unsigned long long liczba) { return liczba % 10000000000000000000ULL; } unsigned long long startHash = 0; unsigned long long endHash = 0; unsigned long long sumaHashy = 0; int main() { std::ios_base::sync_with_stdio(false); char a; do { a = getchar(); } while (isspace(a) || isdigit(a)); unsigned long long i = 1; do { if (isspace(a)) { break; } unsigned long long tenHash = getHash(a); startHash += tenHash * i; sumaHashy += tenHash; endHash += sumaHashy; startHash = obetnij(startHash); endHash = obetnij(endHash); i++; } while ((a = getchar()) != EOF); if (startHash == endHash) { cout << "TAK" <<endl; } else { cout << "NIE" << endl; } return 0; } |