Description
Input
Output
Sample Input
12 1 3 3 4 0 7 3 8 15 19 15 20 10 15 8 18 6 12 5 10 4 14 2 9 0
Sample Output
5
#include<iostream> #include<algorithm> using namespace std; typedef struct st{ int begin; int end; }st; bool cmp(st a,st b) { if(a.begin<b.begin)return true; else return false; } int main() { int n; while(cin>>n) { if(n==0) return 0; st a[1000]; int i; for( i=0;i!=n;i++) cin>>a[i].begin>>a[i].end; sort(a,a+n,cmp); int sum=1; for( i=1;i!=n;i++){ if(a[i].begin<a[i-1].end) { if(a[i].end>a[i-1].end) a[i].end=a[i-1].end; } else { sum++; } } cout<<sum<<endl; } return 0; }