Result: Accepted
Time: 7ms
Memory: 1716kB
#include <bits/stdc++.h>
using namespace std;
struct node
{
int st ;
int ed ;
}arr[110] ;
bool com(node x , node y)
{
if(x.ed != y.ed)
return x.ed < y.ed ;
return x.st < y.st ;
}
int main(int argc, char const *argv[])
{
int n ;
while(scanf("%d",&n)!=EOF)
{
if(n == 0) break ;
for(int i = 0 ; i < n ; ++ i)
{
scanf("%d %d",&arr[i].st,&arr[i].ed) ;
}
sort(arr,arr+n,com) ;
int tot = 1 ;
int pre = arr[0].ed ;
for(int i = 1 ; i < n ; ++ i)
{
if(arr[i].st >= pre)
{
tot ++ ;
pre = arr[i].ed ;
}
}
cout << tot << endl ;
}
return 0;
}