Guest User

Untitled

a guest
Apr 22nd, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. int checker(string a, string b)
  2. {
  3.     unordered_map<int,int> cntA, cntB;
  4.     for(auto i:a)
  5.         cntA[i]++;
  6.     for(auto i:b)
  7.         cntB[i]++;
  8.     int n = cntA['?'];
  9.     for(auto i:cntB)
  10.     {
  11.         if(cntA[i.first] > i.second)
  12.             return 0;
  13.         if(cntA[i.first] < i.second)
  14.         {
  15.             int miss = i.second - cntA[i.first];
  16.             if(n < miss)
  17.                 return 0;
  18.             n-=miss;
  19.         }
  20.     }
  21.     return 1;
  22. }
  23. int countAnagram(std::string s, std::string p)
  24. {
  25.     if(p.size() > s.size())
  26.         return 0;
  27.     int cnt = 0;
  28.     for(int i = 0;i<=s.size() - p.size();i++)
  29.     {
  30.         string tmp = s.substr(i, int(p.size()));
  31.         cnt+= checker(tmp, p);
  32.     }
  33.     return cnt;
  34. }
Add Comment
Please, Sign In to add comment