mfgnik

Untitled

Jun 27th, 2020
1,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <unordered_set>
  4.  
  5. struct Point {
  6.     int x, y;
  7.  
  8.     Point(int x, int y) : x(x), y(y) {}
  9.  
  10.     bool operator<(const Point &other) const {
  11.         return x < other.x or x == other.x and y < other.y;
  12.     }
  13. };
  14.  
  15.  
  16. int main() {
  17.     std::set<Point> points_set;
  18.     int points_amount;
  19.     std::cin >> points_amount;
  20.     for (int index = 0; index < points_amount; ++index) {
  21.         int x, y;
  22.         std::cin >> x >> y;
  23.         points_set.emplace(x, y);
  24.     }
  25.     std::unordered_set<int> x_lines, y_lines;
  26.     auto current_point = points_set.begin();
  27.     auto next_point = std::next(points_set.begin());
  28.     for (; next_point != points_set.end(); ++next_point, ++current_point) {
  29.         if (current_point->x == next_point->x && current_point->y < next_point->y) {
  30.             y_lines.insert(current_point->y + 1);
  31.         } else {
  32.             x_lines.insert(current_point->x + 1);
  33.         }
  34.     }
  35.     std::cout << y_lines.size() + x_lines.size() << "\n";
  36.     for (auto line : y_lines) {
  37.         std::cout << "y " << line << "\n";
  38.     }
  39.     for (auto line : x_lines) {
  40.         std::cout << "x " << line << "\n";
  41.     }
  42. };
Advertisement
Add Comment
Please, Sign In to add comment