Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- using namespace std;
- int A[4][4];
- int main()
- {
- char t;
- int x = 0;
- int y = 0;
- bool ty = false;
- for (int i = 1; i <= 3; i++)
- {
- for (int v = 1; v <= 3; v++)
- {
- cin >> t;
- if (t == '.')
- {
- ty = true;
- A[i][v] = 0;
- }
- if (t == 'X')
- {
- x++;
- A[i][v] = 1;
- }
- if (t == '0')
- {
- y++;
- A[i][v] = -1;
- }
- }
- }
- bool r1 = false;
- bool r2 = false;
- if (((x - y) > 1) || (y > x))
- {
- cout << "illegal";
- return 0;
- }
- for (int i = 1; i <= 3; i++)
- {
- if (A[i][1] + A[i][2] + A[i][3] == 3)
- {
- r1 = true;
- }
- if (A[i][1] + A[i][2] + A[i][3] == -3)
- {
- r2 = true;
- }
- }
- for (int i = 1; i <= 3; i++)
- {
- if (A[1][i] + A[2][i] + A[3][i] == 3)
- {
- r1 = true;
- }
- if (A[1][i] + A[2][i] + A[3][i] == -3)
- {
- r2 = true;
- }
- }
- if (A[1][1] + A[2][2] + A[3][3] == 3)
- {
- r1 = true;
- }
- if (A[1][1] + A[2][2] + A[3][3] == -3)
- {
- r2 = true;
- }
- if (A[1][3] + A[2][2] + A[3][1] == 3)
- {
- r1 = true;
- }
- if (A[1][3] + A[2][2] + A[3][1] == -3)
- {
- r2 = true;
- }
- if (r1&&r2)
- {
- cout << "illegal";
- return 0;
- }
- if ((!r1 && !r2)&&(x+y==9))
- {
- cout << "draw";
- return 0;
- }
- if (r1)
- {
- if (y == x)
- {
- cout << "illegal";
- return 0;
- }
- cout << "the first player won";
- return 0;
- }
- if (r2)
- {
- if (x - y == 1)
- {
- cout << "illegal";
- return 0;
- }
- cout << "the second player won";
- return 0;
- }
- if (x > y)
- {
- cout << "second";
- return 0;
- }
- if (y == x)
- {
- cout << "first";
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement