-
Notifications
You must be signed in to change notification settings - Fork 0
/
17_2.cpp
43 lines (36 loc) · 835 Bytes
/
17_2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// 17_2.cpp
//
//
// Created by Pengyan Qin on 7/18/15.
//
//
#include <iostream>
using namespace std;
// normal tic-tac-toe(3*3)
bool is_won(int A[][3], int n){
for(int i = 0; i < n; ++i){
if(A[i][0] == A[i][1] && A[i][0] == A[i][2]){
return true;
}
if(A[0][i] == A[1][i] && A[0][i] == A[2][i]){
return true;
}
}
if(A[0][0] == A[1][1] && A[0][0] == A[2][2])
return true;
if(A[0][2] == A[1][1] && A[0][2] == A[2][0])
return true;
return false;
}
int main(){
int A[3][3] = {{0, 0, 1},
{1, 1, 0},
{0, 1, 1}};
int n = 3;
int B[3][3] = {{1, 0, 1},
{1, 1, 0},
{0, 0, 1}};
cout << is_won(A, n) << endl;
cout << is_won(B, n) << endl;
}