fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7. std::vector<std::string> my_vec = {"hello","hello","hello","hello","hello"};
  8. std::vector<int> my_count;
  9. for (int i = 0; i < my_vec.size(); ++i)
  10. {
  11. my_count.push_back(1);
  12. for (int j = i + 1; j < my_vec.size(); )
  13. {
  14. if (my_vec[i] == my_vec[j]) {
  15. ++my_count.back();
  16. my_vec.erase(my_vec.begin() + j);
  17. }
  18. else ++j;
  19. }
  20. }
  21.  
  22. for (int i=0; i<my_vec.size(); ++i)
  23. {
  24. std::cout << my_vec[i] << ':' << my_count[i] << '\n';
  25. }
  26. }
Success #stdin #stdout 0s 4272KB
stdin
Standard input is empty
stdout
hello:5