#include #include #include #include using namespace std; struct vect { int x; int y; vect(int a, int b) { x = a; y = b; } }; vect operator -(vect a, vect b) { return vect(a.x - b.x, a.y - b.y); } int dot(vect a, vect b) { return a.x * b.x + a.y * b.y; } int cross(vect a, vect b) { return a.x * b.y - a.y * b.x; } struct shape { char id; vector > lines; vector res; }; bool operator <(const shape& a, const shape& b) { return a.id < b.id; } vect getv() { int a, b; scanf(" (%d,%d)", &a, &b); return vect(2*a, 2*b); } bool cmp(pair m, pair n) { vect a = m.first; vect b = m.second; vect x = n.first; vect y = n.second; vect ab = b - a; vect ax = x - a; vect ay = y - a; int p1 = cross(ab, ax); int p2 = cross(ab, ay); int d1 = dot(ab, ax); int d2 = dot(ab, ay); int d = dot(ab, ab); if ((p1 < 0 && p2 < 0) || (p1 > 0 && p2 > 0)) { return false; } else { if (p1 < 0) { p1 = -p1; } if (p2 < 0) { p2 = -p2; } if (p1 == 0 && p2 == 0) { if ((d1 < 0 && d2 < 0) || (d1 > d && d2 > d)) { return false; } else { return true; } } else { if (p2 * d1 + p1 * d2 >= 0 && p2 * d1 + p1 * d2 <= (p1 + p2) * d) { return true; } else { return false; } } } } int main() { while (true) { char c; char name[100]; vector sh; while (true) { scanf(" %c", &c); if (c == '.') { return 0; } else if (c == '-') { break; } else { sh.push_back(shape()); sh.back().id = c; scanf("%s", name); string n = string(name); if (n == "square") { vect a = getv(); vect c = getv(); vect b = vect(0, 0); vect d = vect(0, 0); b.x = (a.x+(c.y-a.y)+c.x)/2; b.y = (a.y-(c.x-a.x)+c.y)/2; d.x = (a.x-(c.y-a.y)+c.x)/2; d.y = (a.y+(c.x-a.x)+c.y)/2; sh.back().lines.push_back(pair(a, b)); sh.back().lines.push_back(pair(b, c)); sh.back().lines.push_back(pair(c, d)); sh.back().lines.push_back(pair(d, a)); } else if (n == "line") { sh.back().lines.push_back(pair(getv(), getv())); } else if (n == "rectangle") { vect a = getv(); vect b = getv(); vect c = getv(); vect d = vect(c.x+a.x-b.x, c.y+a.y-b.y); sh.back().lines.push_back(pair(a, b)); sh.back().lines.push_back(pair(b, c)); sh.back().lines.push_back(pair(c, d)); sh.back().lines.push_back(pair(d, a)); } else if (n == "triangle") { vect a = getv(); vect b = getv(); vect c = getv(); sh.back().lines.push_back(pair(a, b)); sh.back().lines.push_back(pair(b, c)); sh.back().lines.push_back(pair(c, a)); } else { int k; scanf("%d", &k); vect frst = getv(); vect v1 = vect(0, 0); vect v2 = vect(0, 0); v2 = frst; for (int i = 1; i < k; i ++) { v1 = v2; v2 = getv(); sh.back().lines.push_back(pair(v1, v2)); } sh.back().lines.push_back(pair(frst, v2)); } } } sort(sh.begin(), sh.end()); for (int i = 0; i < (int)sh.size(); i ++) { for (int j = 0; j < (int)sh.size(); j ++) { if (i != j) { bool res = false; for (int p = 0; p < (int)sh[i].lines.size(); p ++) { for (int q = 0; q < (int)sh[j].lines.size(); q ++) { if (cmp(sh[i].lines[p], sh[j].lines[q])) { res = true; } } } if (res) { sh[i].res.push_back(sh[j].id); } } } if (sh[i].res.size() == 0) { printf("%c has no intersections\n", sh[i].id); } else if (sh[i].res.size() == 1) { printf("%c intersects with %c\n", sh[i].id, sh[i].res[0]); } else if (sh[i].res.size() == 2) { printf("%c intersects with %c and %c\n", sh[i].id, sh[i].res[0], sh[i].res[1]); } else { printf("%c intersects with", sh[i].id); for (int j = 0; j < (int)sh[i].res.size() - 1; j ++) { printf(" %c,", sh[i].res[j]); } printf(" and %c\n", sh[i].res[sh[i].res.size() - 1]); } } printf("\n"); } }