View Code of Problem 4044

#include<bits/stdc++.h>
using namespace std;
struct node{
	int be,end;
}stu[22];
bool cmp(struct node x,struct node y){
	if(x.end==y.end)
	return x.be<y.be;
	return x.end<y.end;
}
int main(){
	int n;
	while(cin>>n&&n!=0){
		for(int i=0;i<n;++i)
		scanf("%d%d",&stu[i].be,&stu[i].end);
 		sort(stu,stu+n,cmp);
 		int begin=stu[0].end,ans=0,d=0;
 		while(d<n){
 			if(stu[d].be>=begin){
 				begin=stu[d].end;
 				++ans;
			 }
			 ++d;
		 }
		 cout<<ans+1<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 4044