1007: 矩形着色

原题地址

#include<iostream>
#include<string>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    string* results = new string[n];

    for (int i = 0; i < n; i++) {
        int x, y, lx, ly, rx, ry;
        cin >> x >> y;
        cin >> lx >> ly >> rx >> ry;

        //不在矩形内的情况
        if (x < lx || x > rx || y < ly || y > ry) {
            results[i] = "Outside";
        }
        //在矩形边上的情况
        else if ((x >= lx && x <= rx && (y == ly || y == ry)) || (y >= ly && y <= ry && (x == lx || x == rx))) {
            results[i] = "On";
        }
        //在矩形内部的情况
        else {
            results[i] = "Inside";
        }
    }

    for (int i = 0; i < n; i++) {
        cout << results[i] << endl;
    }

    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章