#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <string> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cstdio> #include <algorithm> #include <stack> #include <iomanip> #include <limits> #include <cctype> using namespace std; int X = 31; int MOD = 1000000007; int main(int argc, char const *argv[]) { std::ios::sync_with_stdio(false); int n; scanf("%i", &n); vector<char> buffer(4096, '\0'); unsigned long long hash_left = 0, hash_right = 0, x = 1; while(fgets(buffer.data(), buffer.size(), stdin)) { for(int i = 0; i < buffer.size(); ++i) { if('a' <= buffer[i] && buffer[i] <= 'z') { hash_left = (hash_left * X + (buffer[i] - 'a')) % MOD; hash_right = (hash_right + (buffer[i] - 'a') * x) % MOD; x = (x * X) % MOD; } else { break; } } } if(hash_left == hash_right) { printf("TAK\n"); } else { printf("NIE\n"); } 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 | #include <iostream> #include <vector> #include <queue> #include <algorithm> #include <string> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cstdio> #include <algorithm> #include <stack> #include <iomanip> #include <limits> #include <cctype> using namespace std; int X = 31; int MOD = 1000000007; int main(int argc, char const *argv[]) { std::ios::sync_with_stdio(false); int n; scanf("%i", &n); vector<char> buffer(4096, '\0'); unsigned long long hash_left = 0, hash_right = 0, x = 1; while(fgets(buffer.data(), buffer.size(), stdin)) { for(int i = 0; i < buffer.size(); ++i) { if('a' <= buffer[i] && buffer[i] <= 'z') { hash_left = (hash_left * X + (buffer[i] - 'a')) % MOD; hash_right = (hash_right + (buffer[i] - 'a') * x) % MOD; x = (x * X) % MOD; } else { break; } } } if(hash_left == hash_right) { printf("TAK\n"); } else { printf("NIE\n"); } return 0; } |