#include <iostream> using namespace std; long long MOD = 1000000123; int maks = 20000000; int pod = 29; int main() { ios_base::sync_with_stdio(0); cin.tie(); long long hasz1 = 0, hasz2 = 0; long long potega = 1; int n; cin >> n; char z; while (cin >> z) { hasz1 = (hasz1 + potega*(z-'a'+1))%MOD; hasz2 = (hasz2*pod + z-'a'+1)%MOD; potega = (pod*potega)%MOD; } if (hasz1 == hasz2) cout << "TAK"; else cout << "NIE"; }
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 | #include <iostream> using namespace std; long long MOD = 1000000123; int maks = 20000000; int pod = 29; int main() { ios_base::sync_with_stdio(0); cin.tie(); long long hasz1 = 0, hasz2 = 0; long long potega = 1; int n; cin >> n; char z; while (cin >> z) { hasz1 = (hasz1 + potega*(z-'a'+1))%MOD; hasz2 = (hasz2*pod + z-'a'+1)%MOD; potega = (pod*potega)%MOD; } if (hasz1 == hasz2) cout << "TAK"; else cout << "NIE"; } |