fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. #include <string>
  6. using namespace std;
  7.  
  8. void parse_string(vector <set <string> > &result) {
  9. map<char, vector<string>> temp;
  10. string word;
  11. while(cin >> word){
  12. temp[word[0]].push_back(word);
  13. }
  14. for(auto p : temp){
  15. set<string> t;
  16. for(auto w : p.second){
  17. t.insert(w);
  18. }
  19. result.push_back(t);
  20. }
  21. for(auto p : result){
  22. for(auto t : p){
  23. cout << t << " ";
  24. }
  25. cout << endl;
  26. }
  27. }
  28.  
  29. int main() {
  30. vector <set <string> > result;
  31. parse_string(result);
  32. return 0;
  33. }
Success #stdin #stdout 0s 15240KB
stdin
aaaa ttt at ah aj tu tg hg hb jx
stdout
aaaa ah aj at 
hb hg 
jx 
tg ttt tu