| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 
 | #include <iostream>#include <vector>
 #include <algorithm>
 
 struct Program {
 int startTime;
 int endTime;
 
 friend bool operator<(const Program& a, const Program& b) {
 return a.endTime < b.endTime;
 }
 
 friend std::istream& operator>>(std::istream& in, Program& program) {
 in >> program.startTime >> program.endTime;
 return in;
 }
 };
 
 int main(int argc, const char * argv[]) {
 
 int size = 0;
 while (std::cin >> size) {
 if (!size) break;
 std::vector<Program> programs(size);
 for (int i = 0; i < size; i++) {
 std::cin >> programs[i];
 }
 std::sort(programs.begin(), programs.end());
 int start = 0;
 int watchCount = 0;
 for (int i = 0; i < size; i++) {
 const Program& program = programs[i];
 if (start > program.startTime) continue;
 watchCount++;
 start = program.endTime;
 }
 std::cout << watchCount << std::endl;
 }
 return 0;
 }
 
 |