王道机试第二版-第七章-例题7.4
今年暑假不AC
#include<bits/stdc++.h> using namespace std; struct program{ int begin; int end; }; bool compare(program a,program b){ return a.end<b.end; } int main(){ int n; while(cin>>n){ if(n==0)break; program arr[n]; for(int i=0;i<n;i++){ cin>>arr[i].begin>>arr[i].end; } sort(arr,arr+n,compare); int answer=1; int now=arr[0].end; for(int i=1;i<n;i++){ if(now<=arr[i].begin){ answer++; now=arr[i].end; } } cout<<answer<<endl; } return 0; }