#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int start = 0;
int end = 0;
int start1;
int end1;
void hebing();
void print();
int main() {
int num = 0;
scanf("%d", &num);
scanf("%d", &start);
scanf("%d", &end);
for (int i = num - 1; i > 0; i--) {
hebing();
}
print();
return 0;
}
//整体思路是对的
//细节要分情况
//写函数然后分类讨论
void hebing() {
start1 = 0;
end1 = 0;
scanf("%d", &start1);
scanf("%d", &end1);
if (start1 <= end && end1 >= end)
{
end = end1;
end1 = 0;
start1 = 0;
}
else if (start1 >= start && end1 <= end) {
start1 = 0;
end1 = 0;
}
else {
print();
start = start1;
end = end1;
start1 = 0;
end1 = 0;
}
}
void print() {
if (start != 0 && end != 0) {
printf("%d %d\n", start, end);
}
}
//输出残余的
区间合并问题(还是很有成就感的,慢慢来)
最新推荐文章于 2024-09-13 14:59:21 发布