Advertisement
AdamTheGreat

Untitled

Jul 15th, 2022
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. int main(void) {
  7. set<int> a;
  8. set<int> b;
  9. int lena, lenb;
  10. cin >> lena >> lenb;
  11. for (int i = 0; i < lena; i++) {
  12. int num;
  13. scanf("%d", &num);
  14. a.insert(num);
  15. }
  16. for (int i = 0; i < lenb; i++) {
  17. int num;
  18. scanf("%d", &num);
  19. b.insert(num);
  20. }
  21. bool asubb = true, bsuba = true, same = true;
  22. if (a.size() == b.size()) {
  23. for (set<int>::iterator it = a.begin(); it != a.end(); it++) {
  24. if (b.count(*it) == 0) {
  25. same = false;
  26. break;
  27. }
  28. }
  29. } else {
  30. same = false;
  31. }
  32. for (set<int>::iterator it = a.begin(); it != a.end(); it++) {
  33. if (b.count(*it) == 0) {
  34. asubb = false;
  35. continue;
  36. }
  37. }
  38. for (set<int>::iterator it = b.begin(); it != b.end(); it++) {
  39. if (a.count(*it) == 0) {
  40. bsuba = false;
  41. continue;
  42. }
  43. }
  44. if (asubb) {
  45. cout << "A is a proper subset of B" << endl;
  46. } else if (bsuba) {
  47. cout << "B is a proper subset of A" << endl;
  48. } else if (same) {
  49. cout << "A and B are disjoint" << endl;
  50. } else {
  51. cout << "I'm confused!" << endl;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement