Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by kuba ( 16 years ago )
#include <iostream>

using namespace std;

int gdzie_krol (char plansza[][9])
{
    int x, y;

    for (int i = 0; i <= 7; i++)
        for (int j = 0; j <= 7; j++)
            if (plansza[i][j] == 'K')
            {
                y = j;
                x = i;
            }

    return x*10+y;
}

void bij (int x, int y, bool szach[][9])
{
    for (int i = 0; i <= 7; i++)
    {
        if (i == x) continue;
        szach[i][y] = true;
    }
    for (int i = 0; i <= 7; i++)
    {
        if (i == y) continue;
        szach[x][i] = true;
    }
}

bool mat (int krolx, int kroly, bool szach[][9])
{
        if (szach[krolx][kroly] == false) return false;

        if (krolx > 0 && kroly > 0)
            if (szach[krolx-1][kroly-1] == false) return false;
        if (krolx < 7 && kroly > 0)
            if (szach[krolx+1][kroly-1] == false) return false;
        if (krolx > 0 && kroly < 7)
            if (szach[krolx-1][kroly+1] == false) return false;
        if (krolx < 7 && kroly < 7)
            if (szach[krolx+1][kroly+1] == false) return false;

        if (krolx > 0)
            if (szach[krolx-1][kroly] == false) return false;
        if (krolx < 7)
            if (szach[krolx+1][kroly] == false) return false;
        if (kroly > 0)
            if (szach[krolx][kroly-1] == false) return false;
        if (kroly < 7)
            if (szach[krolx][kroly+1] == false) return false;

    return true;

}

int main ()
{
    int Z;
    cin >> Z;

    while (Z--)
    {
        char plansza[9][9];
        bool szach[9][9] = {false};

        string temp;

        for (int i = 0; i <= 7; i++)
        {
            cin >> temp;
            for (int j = 0; j <= 7; j++)
            {
                plansza[i][j] = temp[j];
            }
            temp.erase();
        }

        int krol;
        krol = gdzie_krol(plansza);

        int krolx = krol/10, kroly = krol;


        for (int i = 0; i <= 7; i++)
            for (int j = 0; j <= 7; j++)
                if (plansza[i][j] == 'W')
                    bij(i, j, szach);

    /*    for (int i = 0; i <= 7; i++)
        {
            for (int j = 0; j <= 7; j++)
                if (szach[i][j] == true) cout << "X"; else cout << "0";
            cout << endl;
        }
*/
        if (mat(krolx, kroly, szach))
            cout << "mat!\n";
        else
            cout << "gramy dalej!\n";

    }
}

 

Revise this Paste

Your Name: Code Language: