Advertisement
Zuneve

set set 1

Sep 2nd, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <string>
  5. using namespace std;
  6. int main() {
  7. int m, n, k,cnt=0;
  8. cin >> m >> n >> k;
  9. vector <set <int>> a;
  10. set <int> b;
  11. for (int x = 0; x<n; x++) a.push_back(b);
  12. for (int i =0; i<k; i++) {
  13. string s;
  14. cin >> s;
  15. int d,e;
  16. if (s=="ADD") {
  17. cin >> d >> e;
  18. a[e-1].insert(d);
  19. } else if (s=="LISTSET") {
  20. cin >> d;
  21. if (a[d-1].size()==0) cout << -1 << " ";
  22. else {
  23. for( auto c : a[d-1]) cout << c << ' ';
  24. }
  25. } else if (s=="LISTSETSOF") {
  26. cin >> d;
  27. cnt=0;
  28. for ( int j = 0; j<a.size(); j++) {
  29. if (a[j].find(d)!=a[j].end()) {
  30. cout << j+1 << " "; cnt++;
  31. }
  32. } if (cnt==0) cout << -1 << " ";
  33. }
  34. }
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement