Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define NMAX 100
- int n, k;
- struct Time {
- int h, mins;
- bool operator < (const Time &other) const {
- if (h == other.h)
- return mins < other.mins;
- return h < other.h;
- }
- };
- struct Spectacol {
- Time st, sf;
- bool operator < (const Spectacol &other) const {
- return sf < other.sf;
- }
- } vs[NMAX], sol[NMAX];
- void read() {
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> vs[i].st.h >> vs[i].st.mins;
- cin >> vs[i].sf.h >> vs[i].sf.mins;
- }
- }
- void greedy() {
- sol[++k] = vs[1];
- int j = 1;
- for (int i = 2; i <= n; i++) {
- if (vs[j].sf < vs[i].st) {
- sol[++k] = vs[i];
- j = i;
- }
- }
- }
- void display(Spectacol v[]) {
- for (int i = 1; i <= k; i++) {
- cout << "spectacol " << i << " programat de la " << v[i].st.h<< ':' << v[i].st.mins << " la ";
- cout << v[i].sf.h << ':' << v[i].sf.mins << endl;
- }
- }
- int main() {
- read();
- sort(vs + 1, vs + n + 1);//sortez crescator dupa ora de sfarsit
- greedy();
- display(sol);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement