你是说迅雷的笔试题吗?
#include <bits/stdc++.h>
using namespace std;
struct Bound{
unsigned int x;
unsigned int y;
Bound(unsigned int _x=0,unsigned int _y=0)
:x(_x),y(_y){}
};
int main()
{
list<Bound> lst;
unsigned int x,y;
while(scanf("%u,%u",&x,&y)){
lst.emplace_back(x,y);
if(getchar()==10) break;
}
lst.sort([](const Bound& a,const Bound& b){
return a.x<b.x;}
);
for(auto it=++lst.begin();it!=lst.end();++it){
auto cur_it = it;//保存当前迭代器
if(cur_it->x <= (--it)->y){
cur_it->x = it->x;
lst.erase(it);
}
it = cur_it;
}
for(const auto& ele:lst){
printf("%u,%u ",ele.x,ele.y);
}
return 0;
}