提交时间:2023-11-03 13:27:46
运行 ID: 108476
#include <bits/stdc++.h> using namespace std; struct TV { int st , en; }a[1050]; int cmp(const TV x , const TV y) { return x.en < y.en; } int main() { int n; int cur , cnt; while(cin >> n) { if(n == 0) break; for(int i = 0;i < n;i++) { cin >> a[i].st; cin >> a[i].en; } sort(a , a + n , cmp); cur = a[0].en; cnt = 1; for(int i = 1;i < n;i++) { if(a[i].st >= cur) { cur = a[i].en; cnt++; } } cout << cnt << endl; } }