fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <set>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main() {
  9. const multiset<string> words{istream_iterator<string>(cin), istream_iterator<string>()};
  10. auto it = cbegin(words);
  11.  
  12. while(it != cend(words)) {
  13. auto i = words.upper_bound(*it);
  14.  
  15. cout << *it << " appeared: " << distance(it, i) << " times\n";
  16. it = i;
  17. }
  18. }
Success #stdin #stdout 0s 15240KB
stdin
bug
test
test
stdout
bug appeared: 1 times
test appeared: 2 times