fork(1) download
  1. #include <iostream>
  2. #include <utility>
  3. #include <set>
  4. using namespace std;
  5.  
  6. using OP = pair<unsigned, unsigned>;
  7. using SOP = set<OP>;
  8.  
  9.  
  10.  
  11. bool is_symetric (SOP sop) {
  12.  
  13. for (auto it3 = sop.begin(); it3 != sop.end(); it3++) { // loop through each pair in set
  14. if (it3->first != it3->second) {
  15. if (sop.find({it3->second,it3->first })==sop.end()) {
  16. return false;
  17. }
  18. }
  19. }
  20. return true;
  21. }
  22.  
  23. int main() {
  24. SOP test1 { {1,3},{2,4},{5,7},{7,5}, {4,2}, {3,1} };
  25. SOP test2 { {1,3},{2,4},{5,7},{7,5}, {4,2}, {3,1}, {8,4} };
  26.  
  27. cout << is_symetric(test1)<<endl;
  28. cout << is_symetric(test2)<<endl;
  29. return 0;
  30. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1
0