fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Kamus{
  5. map<string, set<string>> k;
  6.  
  7. public:
  8. void tambah(string s, vector<string> v){
  9. for(string t : v){
  10. k[s].insert(t);
  11. k[t].insert(s);
  12. }
  13. }
  14.  
  15. vector<string> ambilSinonim(string s){
  16. vector<string> arr;
  17. for(string t : k[s]) arr.push_back(t);
  18. return arr;
  19. }
  20. };
  21.  
  22. int main(){
  23. Kamus kamus;
  24. kamus.tambah("big", {"large", "great"});
  25. kamus.tambah("big", {"huge", "fat"});
  26. kamus.tambah("huge", {"enormous", "gigantic"});
  27.  
  28. for(auto s : kamus.ambilSinonim("big")){
  29. cout << s << ' ';
  30. }
  31. cout << "\n\n";
  32.  
  33. for(auto s : kamus.ambilSinonim("huge")){
  34. cout << s << ' ';
  35. }
  36. cout << "\n\n";
  37.  
  38. for(auto s : kamus.ambilSinonim("gigantic")){
  39. cout << s << ' ';
  40. }
  41. cout << "\n\n";
  42.  
  43. for(auto s : kamus.ambilSinonim("colossal")){
  44. cout << s << ' ';
  45. }
  46. cout << "\n\n";
  47.  
  48. }
  49.  
  50. /*
  51.  
  52.  
  53. */
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
fat great huge large 

big enormous gigantic 

huge