fork(1) download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main() {
  8. using mmap = map<string, int>; mmap freq;
  9.  
  10. int n;
  11. string word;
  12.  
  13. do {
  14. freq.clear();
  15.  
  16. cin >> n;
  17. if (n < 1 || n > 100000) return 0;
  18.  
  19. for (int i = 0; i < n; i++)
  20. {
  21. cin >> word;
  22. freq[word]++;
  23. }
  24.  
  25. auto iter = max_element(begin(freq), end(freq), []
  26. (const mmap::value_type& a, const mmap::value_type& b){ return a.second < b.second; });
  27.  
  28. if ((iter == end(freq)) || any_of(next(iter), end(freq), [&](const mmap::value_type& a){ return a.second == iter->second; }))
  29. cout << "none" << endl;
  30. else
  31. cout << iter->first << endl;
  32.  
  33. //system("pause");
  34. }
  35. while (true);
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 15240KB
stdin
5 apple apple banana apple banana
4 apple banana apple banana
2 apple banana
0
stdout
apple
none
none