Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<set>
- #include<vector>
- #include<algorithm>
- #include<set>
- #include<vector>
- #include<string>
- #include<stdlib.h>
- #include<math.h>
- #include<stdio.h>
- using namespace std;
- int main()
- {
- int q[4][4];
- char a;
- int xs, zs, h;
- xs = zs = h = 0;
- bool ansx = false, ansz = false;
- for (int i = 1; i <= 3; i++)
- {
- for (int j = 1; j <= 3; j++)
- {
- cin >> a;
- if (a == 'X')
- {
- xs++;
- q[i][j] = 1;
- }
- if (a == '0')
- {
- zs++;
- q[i][j] = -1;
- }
- if (a == '.')
- {
- q[i][j] = 0;
- }
- }
- }
- for (int i = 1; i < 4; i++)
- {
- int rt = 7;
- if (q[i][1] + q[i][2] + q[i][3] == 3)
- ansx = true;
- if (q[1][i] + q[2][i] + q[3][i] == 3)
- ansx = true;
- if (q[i][1] + q[i][2] + q[i][3] == -3)
- ansz = true;
- if (q[1][i] + q[2][i] + q[3][i] == -3)
- ansz = true;
- }
- if (q[1][3] + q[2][2] + q[3][1] == 3)
- {
- ansx = true;
- h++;
- }
- if (q[1][1] + q[2][2] + q[3][3] == 3)
- {
- ansx = true;
- h++;
- }
- if (q[1][3] + q[2][2] + q[3][1] == -3)
- {
- ansz = true;
- }
- if (q[1][1] + q[2][2] + q[3][3] == -3)
- {
- ansz = true;
- }
- if (((xs - zs) > 1) || (zs > xs) || (ansx && ansz))
- {
- cout << "illegal";
- return 0;
- }
- if (zs + xs == 9)
- {
- if (!ansz && !ansx)
- {
- cout << "draw" << endl;
- return 0;
- }
- else
- {
- if ((ansx) && (!ansz))
- {
- cout << "the first player won" << endl;
- return 0;
- }
- else
- {
- if ((ansz) && (!ansx))
- {
- cout << "the second player won" << endl;
- return 0;
- }
- else
- {
- cout << "illegal" << endl;
- return 0;
- }
- }
- }
- }
- else
- {
- if (xs + zs < 9)
- {
- if (!ansx && !ansz)
- {
- if (xs == zs)
- {
- cout << "first" << endl;
- return 0;
- }
- else
- {
- if (xs == zs + 1)
- {
- cout << "second" << endl;
- return 0;
- }
- else
- {
- cout << "illegal" << endl;
- return 0;
- }
- }
- }
- else
- {
- if ((ansx) && (!ansz))
- {
- cout << "the first player won" << endl;
- return 0;
- }
- else
- {
- if ((ansz) && (!ansx))
- {
- cout << "the second player won" << endl;
- return 0;
- }
- else
- {
- cout << "illegal" << endl;
- return 0;
- }
- }
- }
- }
- else
- {
- cout << "illegal" << endl;
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement