Advertisement
Derga

Untitled

Aug 10th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. struct lesson {
  7.     double start;
  8.     double finish;
  9.     bool operator < (lesson& rhs) {
  10.         return finish < rhs.finish;
  11.     }
  12. };
  13.  
  14. int main() {
  15.     int n;
  16.     cin >> n;
  17.  
  18.     if (n == 0) {
  19.         cout << 0;
  20.         return 0;
  21.     }
  22.  
  23.     vector <lesson> v(n);
  24.     for (auto& elem : v) {
  25.         cin >> elem.start;
  26.         cin >> elem.finish;
  27.     }
  28.  
  29.     sort(v.begin(), v.end());
  30.  
  31.     vector <int> result;
  32.     result.push_back(0);
  33.  
  34.     for (int i = 1; i < v.size(); ++i) {
  35.         if (v[result.back()].finish > v[i].start) {
  36.             continue;
  37.         }
  38.         result.push_back(i);
  39.     }
  40.  
  41.     cout << result.size() << endl;
  42.     for (int i = 0; i < result.size(); ++i) {
  43.         cout << v[result[i]].start << " " << v[result[i]].finish << endl;
  44.     }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement