Advertisement
despotovski01

Plagijati

May 10th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. const int MAX_N = 100010;
  6. const int MAX_P = 60;
  7. char s[MAX_N];
  8. int ls;
  9. char p[MAX_P];
  10.  
  11. class trieNode {
  12. public:
  13.     unordered_map<char, trieNode*> nodes;
  14.     char c;
  15.     int match;
  16.     trieNode(char c){
  17.         this->c = c;
  18.         this->match = 0;
  19.     }
  20.  
  21.     void add(char* s, int len){
  22.         trieNode* root = this;
  23.         for(int i = 0;i<len;++i){
  24.             if(root->nodes.find(s[i]-'a') == root->nodes.end()){
  25.                 root->nodes[s[i]-'a'] = new trieNode(s[i]);
  26.             }
  27.             root = root->nodes[s[i]-'a'];
  28.         }
  29.         (root->match)++;
  30.     }
  31.  
  32.     int search(char* s, int len){
  33.         trieNode* root = this;
  34.         for(int i = 0;i<len;++i){
  35.             if(root->nodes.find(s[i]-'a') == root->nodes.end()){
  36.                 return 0;
  37.             }
  38.             root = root->nodes[s[i]-'a'];
  39.         }
  40.         return root->match;
  41.     }
  42.  
  43.     void deleteNode(){
  44.         for(auto it = nodes.begin(); it != nodes.end();++it){
  45.             it->second->deleteNode();
  46.         }
  47.     }
  48. };
  49.  
  50.  
  51. int getRes(int n){
  52.     trieNode* root = new trieNode('\0');
  53.     for(int i = 0;i<n;++i){
  54.         cin>>p;
  55.         root->add(p, strlen(p));
  56.     }
  57.     int res = 0;
  58.     int lp = strlen(p);
  59.     for(int i = 0;i<ls-lp+1;++i){
  60.         res += root->search(s+i, lp);
  61.     }
  62.     root->deleteNode();
  63.     delete root;
  64.     return res;
  65. }
  66.  
  67. int main(){
  68.     ios::sync_with_stdio(false);
  69.     int a, b, c;
  70.     cin>>a>>b>>c;
  71.     cin>>s;
  72.     ls = strlen(s);
  73.     int res = 0;
  74.     res += getRes(a);
  75.     res += getRes(b);
  76.     res += getRes(c);
  77.     cout<<res<<endl;
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement