题解 | #最小长方形#
最小长方形
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。
关于单链表的插入,一定要格外注意。

