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, ansx, ansz;
- xs = zs = ansx = ansz = 0;
- 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++)
- {
- if (q[i][1] + q[i][2] + q[i][3] == 3)
- ansx++;
- if (q[1][i] + q[2][i] + q[3][i] == 3)
- ansx++;
- if (q[i][1] + q[i][2] + q[i][3] == -3)
- ansz++;
- if (q[1][i] + q[2][i] + q[3][i] == -3)
- ansz++;
- }
- if (q[1][3] + q[2][2] + q[3][1] == 3)
- ansx++;
- if (q[1][1] + q[2][2] + q[3][3] == 3)
- ansx++;
- if (q[1][3] + q[2][2] + q[3][1] == -3)
- ansz++;
- if (q[1][1] + q[2][2] + q[3][3] == -3)
- ansz++;
- if (zs > xs || xs - 1 > zs || ansx + ansz > 1)
- {
- cout << "illegal" << endl;
- return 0;
- }
- if (xs + zs < 9)
- {
- if (!(ansx + ansz))
- {
- if (xs == zs + 1)
- {
- cout << "second" << endl;
- return 0;
- }
- if (xs == zs)
- {
- cout << "first" << endl;
- return 0;
- }
- }
- if (ansx == 1 && !ansz)
- {
- cout << "the first player won" << endl;
- return 0;
- }
- if (ansz == 1 && !ansx)
- {
- cout << "the second player won" << endl;
- return 0;
- }
- }
- else
- {
- if (!(ansx + ansz))
- {
- cout << "draw" << endl;
- return 0;
- }
- if (ansx == 1 && !ansz)
- {
- cout << "the first player won" << endl;
- return 0;
- }
- if (ansz == 1 && !ansx)
- {
- cout << "the second player won" << endl;
- return 0;
- }
- }
- cout << "illegal" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement