Untitled

 avatar
unknown
c_cpp
2 years ago
2.1 kB
7
Indexable
#include <iostream>
#include <unordered_map>
using namespace std;
 
struct Key {
    int x;
    int y;
};
 
void FindGhost(unordered_map<int, Key>& k, int x, int y) {
    bool flag = true;
    for (const auto& [id, key] : k)
    {
        if(key.x == x && key.y == y) {
            cout << "Find ghosy key: ";
            cout << id << endl;
            flag = false;
        }
    }
    if(flag) cout << "Not ghost key condition!" << endl;
     
}
 
 
int main() {
    int N, M, K, Q;
    cin >> N >> M >> K >> Q;
    unordered_map<int, Key> Keys;
     
    int key, x, y;
    for (int i = 1; i <= K; i++) {
        cin >> key >> x >> y;
        Keys[key].x = x;
        Keys[key].y = y;
    }
 
    int a, b, c;
 
    for (int i = 0; i < Q; i++) {
        bool flag = true;
        cin >> a >> b >> c;
 
        if(a != b && a != c && b != c) {
            flag = false;
             
            if (Keys[a].x == Keys[b].x && Keys[a].y == Keys[c].y) {
                FindGhost(Keys, Keys[c].x, Keys[b].y);
                continue;
            }else
            if (Keys[a].y == Keys[b].y && Keys[a].x == Keys[c].x) {
                FindGhost(Keys, Keys[b].x, Keys[c].y);
                continue;
            }else
            if (Keys[b].x == Keys[a].x && Keys[b].y == Keys[c].y) {
                FindGhost(Keys, Keys[c].x, Keys[a].y);
                continue;
            }else
            if (Keys[b].y == Keys[a].y && Keys[b].x == Keys[c].x) {
                FindGhost(Keys, Keys[a].x, Keys[c].y);
                continue;
            }else
            if (Keys[c].x == Keys[a].x && Keys[c].y == Keys[b].y) {
                FindGhost(Keys, Keys[b].x, Keys[a].y);
                continue;
            }else
            if (Keys[c].y == Keys[a].y && Keys[c].x == Keys[b].x) {
                FindGhost(Keys, Keys[a].x, Keys[b].y);
                continue;
            }
            else {
                cout << "Not ghost key condition!" << endl;
            }
        }
        if(flag) cout << "Not ghost key condition!" << endl;
    }
}
Editor is loading...