iscsi

SRM 489 D2 250 BadVocabulary

Aug 26th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cctype>
  12. #include <cmath>
  13. using namespace std;
  14. typedef long long LL;
  15. #define FOR(k,a,b) for(int k(a); k < (b); ++k)
  16. #define REP(k,a) for(int k=0; k < (a); ++k)
  17.  
  18.  
  19. class BadVocabulary {
  20. public:
  21.     int count(string badPrefix, string badSuffix, string badSubstring, vector <string> vocabulary) {
  22.         int res=vocabulary.size();
  23.         REP(i,vocabulary.size())
  24.         {
  25.             const string& s=vocabulary[i];
  26.             if(s.length() >= badPrefix.length() && s.substr(0,badPrefix.length())==badPrefix)
  27.                 continue;
  28.             if(s.length() >= badSuffix.length() && s.substr(s.size()-badSuffix.length(),badSuffix.length())==badSuffix)
  29.                 continue;
  30.             if(s.substr(1,s.length()-2).find(badSubstring)!=string::npos )
  31.                 continue;
  32.             --res;
  33.         }
  34.         return res;
  35.     }
  36. };
Advertisement
Add Comment
Please, Sign In to add comment