AC代码:
#include <iostream> #include <cstdio> #include <algorithm> #define Max 105 using namespace std;struct TimeList {int start;int end; }timelist[Max]; bool compare(TimeList a, TimeList b) {if(a.end == b.end)return a.start < b.start;elsereturn a.end < b.end; }int main(void) {freopen("in.txt","r",stdin);int N;while(scanf("%d",&N) && N) //输入N {for(int i = 1; i <= N; i++) //输入时间表 scanf("%d%d",&timelist[i].start,&timelist[i].end);sort(timelist + 1, timelist + 1 + N, compare);int count = 1, sign = 1, start = timelist[1].start, end = timelist[1].end;for(int i = 2; i <= N; i++){if(timelist[i].start >= end){sign++;start = timelist[i].start;end = timelist[i].end;}}printf("%d\n",sign);}fclose(stdin);system("pause");return 0; }