Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <unordered_set>
- #include <iostream>
- #include <set>
- template<class T, class TIter = typename T::iterator, class TVal = typename T::value_type>
- class PairedImpl {
- T& m_t;
- public:
- class Iter {
- TIter m_it;
- public:
- Iter(const TIter & it) : m_it(it) {}
- bool operator!=(const Iter& it) { return m_it != it.m_it; }
- Iter& operator++() { ++m_it; return *this; }
- const Iter & operator *() const { return *this; }
- const TVal & current_point() const { return *m_it; }
- const TVal & next_point() const { return *std::next(m_it); }
- };
- PairedImpl(T& t) : m_t(t) {}
- Iter begin() { return Iter(m_t.begin()); }
- Iter end() {
- TIter end = m_t.end();
- return Iter(m_t.empty() ? end : --end);
- }
- };
- template<class T>
- PairedImpl<T> Paired(T& t) {
- return PairedImpl<T>(t);
- }
- struct Point {
- int x, y;
- Point(int x, int y) : x(x), y(y) {}
- bool operator<(const Point& other) const {
- return x < other.x or x == other.x and y < other.y;
- }
- };
- int main() {
- std::set<Point> points_set;
- int points_amount;
- std::cin >> points_amount;
- for (int index = 0; index < points_amount; ++index) {
- int x, y;
- std::cin >> x >> y;
- points_set.emplace(x, y);
- }
- std::unordered_set<int> x_lines, y_lines;
- for (auto pair : Paired(points_set)) {
- if (pair.current_point().x == pair.next_point().x && pair.current_point().y < pair.next_point().y) {
- y_lines.insert(pair.current_point().y + 1);
- } else {
- x_lines.insert(pair.current_point().x + 1);
- }
- }
- std::cout << y_lines.size() + x_lines.size() << "\n";
- for (auto line : y_lines) {
- std::cout << "y " << line << "\n";
- }
- for (auto line : x_lines) {
- std::cout << "x " << line << "\n";
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment