区间合并问题(还是很有成就感的,慢慢来)

#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);
    }
}
//输出残余的

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值