Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. bool check(const std::string& s, const std::vector<std::string>& d)
  2. {
  3. auto ts = s;
  4.  
  5. while (true)
  6. {
  7. auto match = std::make_pair(ts.npos, 0);
  8.  
  9. for (auto&& w : d)
  10. {
  11. auto pos = ts.find(w);
  12.  
  13. if (pos != ts.npos && w.length() > match.second)
  14. {
  15. match = std::make_pair(pos, w.length());
  16. }
  17. }
  18.  
  19. if (match.first == ts.npos)
  20. break;
  21.  
  22. ts.erase(match.first, match.second);
  23. ts.insert(match.first, "\1");
  24. }
  25.  
  26. for (auto c : ts)
  27. {
  28. if (c != '\1')
  29. {
  30. return false;
  31. }
  32. }
  33.  
  34. return true;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement