fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <unordered_map>
  4. #include <set>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. string text, cacheWord, word;
  11. getline(cin, text);
  12. getline(cin, cacheWord);
  13.  
  14. unordered_map<string, int> freqMap;
  15. set<string> excludedWords;
  16.  
  17. stringstream ss(cacheWord);
  18. while (ss >> word) {
  19. excludedWords.insert(word);
  20. }
  21.  
  22. stringstream textStream(text);
  23. while (textStream >> word) {
  24. if (excludedWords.find(word) == excludedWords.end()) {
  25. freqMap[word]++;
  26. }
  27. }
  28.  
  29. string result = "";
  30. int maxFreq = 0;
  31.  
  32. for (const auto &entry : freqMap) {
  33. if (entry.second > maxFreq || (entry.second == maxFreq && entry.first < result)) {
  34. maxFreq = entry.second;
  35. result = entry.first;
  36. }
  37. }
  38.  
  39. cout << result << endl;
  40. return 0;
  41. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout