View Code of Problem 4044

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
struct program {
	int start;
	int end;
};
bool cmp(program p1, program p2) {
	return p1.end < p2.end;
}
int main()
{
	int n;
	while (cin >> n && n != 0) {
		vector<program>vec;
		for (int i = 0; i < n; i++) {
			program p;
			cin >> p.start >> p.end;
			vec.push_back(p);
		}
		sort(vec.begin(), vec.end(), cmp);
		int curtime = 0;
		int count = 0;
		for (int i = 0; i < vec.size(); i++) {
			if (vec[i].start >= curtime) {
				count++;
				curtime = vec[i].end;
			}
		}
		cout << count << endl;
	}
	
	
	return 0;
}

Double click to view unformatted code.


Back to problem 4044