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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章