提交时间:2023-11-06 20:50:11
运行 ID: 109176
#include<bits/stdc++.h> using namespace std; struct jiemu{ int begin,end; }a[105]; bool cmp(jiemu a,jiemu b){ if(a.end!=b.end)return a.end<b.end; return a.begin>b.begin; } int n,now,ans; int main(){ while(cin>>n&&n){ now=ans=0; for(int i=1;i<=n;i++){ cin>>a[i].begin>>a[i].end; } sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++){ if(now<=a[i].begin){ now=a[i].end; ans++; } } cout<<ans<<endl; } return 0; }