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

big enormous gigantic 

huge 

NULL