今年暑假不AC

#include <cstdio>
#include <algorithm>
using namespace std;

typedef struct
{
	int s;
	int e;
}Ti;

bool cmp(const Ti &a, const Ti &b)
{
	return a.e < b.e;
}

int main()
{
	int n;
	while(scanf("%d", &n) && n != 0)
	{
		Ti t[n];
		int sum = 1;
		
		for(int i = 0; i < n; ++ i)
		{
			scanf("%d %d", &t[i].s, &t[i].e);
		}
		
		sort(t, t + n, cmp);
		
		Ti k = t[0];
		for(int i = 1; i < n; ++ i)
		{
			if(t[i].s >= k.e)
			{
				k = t[i];
				sum ++;
			}
		}
		printf("%d
", sum);
	}
	
	return 0;
}

  

原文地址:https://www.cnblogs.com/mjn1/p/11283466.html