【題解】ZeroJudge d596: 1. 猜九宮格裡的地雷

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=d596

#include <iostream>
#include <vector>
using namespace std;

int t, a, b, c, ans[10];
vector <int> v[10] = {{}, {2, 4}, {1, 3, 5}, {2, 6}, {1, 5, 7}, {2, 4, 6, 8}, {3, 5, 9}, {4, 8}, {5, 7, 9}, {6, 8}};

int main(int argc, const char * argv[]) {
    cin >> t;
    while (t--){
        cin >> a >> b >> c;
        for (int i:v[a]){
            ans[i] = 1;
        }
        for (int i:v[b]){
            ans[i] = 0;
        }
        for (int i:v[c]){
            ans[i] = 0;
        }
        bool flag = false;
        for (int i = 1; i <= 9; i++){
            if (ans[i]){
                ans[i] = 0;
                cout << i << " ";
                flag = true;
            }
        }
        if (!flag) cout << "Empty";
        cout << "\n";
    }
}
分享本文 Share with friends