今年暑假不AC
![](https://i-blog.csdnimg.cn/blog_migrate/a5d6a854b54b7f00f282f4dca69e9531.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2d6c348a7cd1587dc1753fae209292b8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/95ca640caf5d24c50d2f3e2582c962aa.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c9c5bea0940dbc7374b92c85dca36c36.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a5bf6bcbbcfda4ad798a9b9db3618924.png)
参考代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 101;
struct program {
int startTime;
int endTime;
};
program arr[MAXN];
bool cmp(program x , program y ){//按照结束时间最早排序
return x.endTime<y.endTime;
}
int main(){
int n;
while(cin >> n){
if(n == 0)
break;
for(int i = 0; i < n; i++){
cin>>arr[i].startTime>>arr[i].endTime;
}
sort(arr,arr+n,cmp);
int current = 0;
int answer = 0;
for(int i = 0 ; i<n ;i++){
if(current <= arr[i].startTime){
current = arr[i].endTime;
answer++;
}
}
cout<<answer<<endl;
}
return 0;
}