题解 | #最小长方形#

最小长方形

https://www.nowcoder.com/practice/dc6a75a15d1948edafa6d63bc8fc2368

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
using namespace std;
typedef struct rect {
    int x, y;
    rect* next;
} rect;

int main() {
    while (true) {
        rect* head=new rect;
        head->next=NULL; 
        rect *p;
        p = head;
        while (true) {
            rect* xx = new rect;
            xx->next==NULL;
            cin >> xx->x >> xx->y;
            if (xx->x == 0 && xx->y == 0)
                break;
            xx->next=p->next;
            p->next = xx;
            p = p->next;
        }
        if (head->next == NULL)
            break;
        int minx = head->next->x, miny = head->next->y;
        int maxx = head->next->x, maxy = head->next->y;
        for (p = head->next->next; p != NULL; p = p->next) {
            if (minx > p->x)
                minx = p->x;
            if (maxx < p->x)
                maxx = p->x;
            if (miny > p->y)
                miny = p->y;
            if (maxy < p->y)
                maxy = p->y;
        }
        cout << minx << " " << miny << " " << maxx << " " << maxy << endl;
    }

    return 0;
}

就是这个,我看好像没有人使用单链表来做,我就突发奇想想要试一试,但是没想到一直提示段错误,然后经过排查,发现连最基本的数据结构都用错了o(╥﹏╥)o。

关于单链表的插入,一定要格外注意。

全部评论

相关推荐

牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务