Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdint>
- using namespace std;
- template <unsigned int M, unsigned int base>
- class hashh{
- public:
- hashh(): val(0),rp(1) {};
- uint32_t val;
- uint32_t rp;
- void add(uint32_t a){
- val = (val + rp*a)%M;
- rp=(rp*base)%M;
- }
- };
- template <unsigned int M, unsigned int base>
- class rev_hash{
- public:
- rev_hash(): val(0) {};
- uint32_t val;
- void add(uint32_t b0){
- val = (val*base + b0)%M;
- }
- };
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n;
- cin >> n;
- hashh<32711, 31> h1;
- rev_hash<32711, 31> rh1;
- hashh<32999, 29> h2;
- rev_hash<32999, 29> rh2;
- hashh<42709, 29> h3;
- rev_hash<42709, 29> rh3;
- char c;
- while (cin >> c && isalpha(c)) {
- uint32_t t = c - 'a';
- h1.add(t);
- rh1.add(t);
- h2.add(t);
- rh2.add(t);
- h3.add(t);
- rh3.add(t);
- }
- cout<< ((rh1.val==h1.val && rh2.val==h2.val && rh3.val==h3.val)?"TAK":"NIE")<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement