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.  
  19. return arr;
  20. }
  21. };
  22.  
  23. int main(){
  24. Kamus kamus;
  25. kamus.tambah("big", {"large", "great"});
  26. kamus.tambah("big", {"huge", "fat"});
  27. kamus.tambah("huge", {"enormous", "gigantic"});
  28.  
  29. for(auto s : kamus.ambilSinonim("big")){
  30. cout << s << ' ';
  31. }
  32. cout << "\n\n";
  33.  
  34. for(auto s : kamus.ambilSinonim("huge")){
  35. cout << s << ' ';
  36. }
  37. cout << "\n\n";
  38.  
  39. for(auto s : kamus.ambilSinonim("gigantic")){
  40. cout << s << ' ';
  41. }
  42. cout << "\n\n";
  43.  
  44. if(kamus.ambilSinonim("colossal").empty()){
  45. cout << "NULL" << '\n';
  46. }
  47. for(auto s : kamus.ambilSinonim("colossal")){
  48. cout << s << ' ';
  49. }
  50. cout << "\n\n";
  51.  
  52. }
  53.  
  54. /*
  55.  
  56.  
  57. */
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
fat great huge large 

big enormous gigantic 

huge 

NULL