Advertisement
STANAANDREY

nr of rect with lines ll with Ox, Oy

Jan 16th, 2022
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define x first
  3. #define y second
  4. using namespace std;
  5. using Point = pair<int, int>;
  6.  
  7. istream &operator >> (istream &in, Point &point) {
  8.     in >> point.x >> point.y;
  9.     return in;
  10. }
  11.  
  12. int solve(const set<Point> &points) {
  13.     int ans = 0;
  14.     set<Point>::const_iterator it1, it2;
  15.     for (it1 = cbegin(points); it1 != cend(points); it1++) {
  16.         it2 = it1;
  17.         advance(it2, 1);
  18.         for (; it2 != cend(points); it2++) {
  19.             if (it1->x == it2->x || it1->y == it2->y) {
  20.                 continue;
  21.             }
  22.  
  23.             const auto &p3 = Point(it1->x, it2->y);
  24.             const auto &p4 = Point(it2->x, it1->y);
  25.  
  26.             if (points.count(p3) && points.count(p4)) {
  27.                 ans++;
  28.             }
  29.         }
  30.     }
  31.     return ans >> 1;
  32. }
  33.  
  34. signed main() {
  35.     int n;
  36.     cin >> n;
  37.     vector<Point> points(n);
  38.     for (auto &point : points) {
  39.         cin >> point;
  40.     }//*/
  41.     cout << "Nr. of rectangles with lines || with Ox, Oy is: ";
  42.     cout << solve(set<Point>(cbegin(points), cend(points))) << endl;
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement