Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. string mostCommonWord(string p, vector<string>& banned) {
  2.         unordered_set<string> ban(banned.begin(), banned.end());
  3.         unordered_map<string, int> count;
  4.         for (auto & c: p) c = isalpha(c) ? tolower(c) : ' ';
  5.         istringstream iss(p);
  6.         string w;
  7.         pair<string, int> res ("", 0);
  8.         while (iss >> w)
  9.             if (ban.find(w) == ban.end() && ++count[w] > res.second)
  10.                 res = make_pair(w, count[w]);
  11.         return res.first;
  12.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement