UVa 10363 Tic Tac Toe

 1  #include <stdio.h>
 2  #include <stdlib.h>
 3  #include <iostream>
 4  #include <algorithm>
 5  #include <string.h>
 6  #include <map>
 7  using namespace std;
 8  char arr[5][5];
 9  int main()
10  {
11      int cas;
12      cin>>cas;
13      while(cas--)
14      {
15          int o=0,x=0;
16 
17          for(int i=0; i<3; i++)
18          {
19              for(int j=0; j<3; j++)
20              {
21                  cin>>arr[i][j];
22                  if(arr[i][j]=='O') o+=1;
23                  else if(arr[i][j]=='X') x+=1;
24              }
25          }
26          bool xxflag=false;
27          bool ooflag=false;
28          for(int i=0; i<3; i++)
29          {
30              bool xflag=true;
31              bool oflag=true;
32              for(int j=0; j<3; j++)
33              {
34                  if(arr[i][j]!='O') oflag=false;
35                  if(arr[i][j]!='X') xflag=false;
36              }
37              if(oflag==true) ooflag=true;
38              if(xflag==true) xxflag=true;
39          }
40          for(int i=0; i<3; i++)
41          {
42              bool xflag=true;
43              bool oflag=true;
44              for(int j=0; j<3; j++)
45              {
46                  if(arr[j][i]!='O') oflag=false;
47                  if(arr[j][i]!='X') xflag=false;
48              }
49              if(oflag==true) ooflag=true;
50              if(xflag==true) xxflag=true;
51          }
52          if(arr[0][0]=='O'&&arr[1][1]=='O'&&arr[2][2]=='O') ooflag=true;
53          else if(arr[0][0]=='X'&&arr[1][1]=='X'&&arr[2][2]=='X') xxflag=true;
54          if(arr[0][2]=='O'&&arr[1][1]=='O'&&arr[2][0]=='O') ooflag=true;
55          else if(arr[0][2]=='X'&&arr[1][1]=='X'&&arr[2][0]=='X') xxflag=true;
56          bool ans=true;
57          if(ooflag==true && x!=o) ans=false;
58          if(o>x) ans=false;
59          if(xxflag==true && x==o) ans=false;
60          if(x-o>=2) ans=false;
61          if(ooflag==true && xxflag==true) ans=false;
62          if(ans==false) cout<<"no"<<endl;
63          else cout<<"yes"<<endl;
64      }
65      return 0;

66  }

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble