通过率50%
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct myT {
int beg;
int end;
int length;
};
bool cmp(const myT& a, const myT& b) {
if (a.length == b.length) return a.beg<b.beg;
return a.length>b.length;
}
int main() {
vector<myT> num;
int one, two;
char ch;
while (cin >> one >> ch >> two) {
if (!one && !two) break;
if (one<8 || two>21 || one >= two) continue;
myT temp;
temp.beg = one;
temp.end = two;
temp.length = two - one;
num.push_back(temp);
}
sort(num.begin(), num.end(), cmp);
int len = num.size(), lastEnd = num[0].end;
vector<myT> res;
res.push_back(num[0]);
for (int i = 1; i<len; ++i) {
if (num[i].beg<lastEnd) continue;
else {
res.push_back(num[i]);
lastEnd = num[i].end;
}
}
//sort(res.begin(), res.end(), cmp2);
for (auto ele : res) cout << ele.beg << ',' << ele.end << endl;
return 0;
}