fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <unordered_map>
  5. using namespace std;
  6.  
  7. unordered_map <string, unsigned> uniqueWords;
  8.  
  9. bool compare(string a, string b) {
  10. return uniqueWords[a] > uniqueWords[b];
  11. }
  12.  
  13. int main() {
  14. vector<string> words;
  15. for (string s; cin >> s;) {
  16. words.push_back(s);
  17. ++uniqueWords[s];
  18. }
  19. sort(words.begin(), words.end(), compare);
  20. for (auto c : words) {
  21. if (uniqueWords[c]) {
  22. cout << c << ' ';
  23. uniqueWords[c] = 0;
  24. }
  25. }
  26. }
Success #stdin #stdout 0.01s 5544KB
stdin
A B HELLO HELLO
stdout
HELLO A B