标签:
题目大意:
#include <iostream> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <cstdio> #include <vector> #include <cstdlib> using namespace std; typedef __int64 LL; const LL INF = 0xffffff; const int maxn = 100005; const LL MOD = 1e9+7; #define Illegal 0 ///判断这个局面不合法 #define First 1 ///该第一个人了 #define Second 2 ///该第二个人了 #define Draw 3 ///平局 #define Tfpw 4 ///这个局面刚出来F就赢了 #define Tspw 5 ///这个局面刚出来S就赢了 char maps[5][5]; bool Ok(int x,int y) { return x>=0 && x<3 && y>=0 && y < 3; } bool Win(char ch) { for(int i=0; i<3; i++) { if(maps[0][i] == ch && maps[1][i] == ch && maps[2][i] == ch) return true; if(maps[i][0] == ch && maps[i][1] == ch && maps[i][2] == ch) return true; } if(maps[0][0] == ch && maps[1][1] == ch && maps[2][2] == ch) return true; if(maps[0][2] == ch && maps[1][1] == ch && maps[2][0] == ch) return true; return false; } int solve() { int numX = 0, num0 = 0; for(int i=0; i<3; i++) for(int j=0; j<3; j++) { if(maps[i][j] == ‘X‘) numX ++; if(maps[i][j] == ‘0‘) num0 ++; } if( !(numX - num0 == 0 || numX - num0 == 1) || (Win(‘X‘) && Win(‘0‘) ) || (Win(‘X‘) && numX - num0 != 1) || (Win(‘0‘) && numX - num0 != 0)) return Illegal; if(Win(‘X‘)) return Tfpw; if(Win(‘0‘) && numX - num0 == 0) return Tspw; if(num0 == 4 && numX == 5) return Draw; if(numX - num0 == 0) return First; if(numX - num0 == 1) return Second; return 0; } int main() { for(int i=0; i<3; i++) scanf("%s", maps[i]); int ans = solve(); if(ans == Illegal) puts("illegal"); else if(ans == First) puts("first"); else if(ans == Draw) puts("draw"); else if(ans == Second) puts("second"); else if(ans == Tfpw) puts("the first player won"); else if(ans == Tspw) puts("the second player won"); return 0; }
标签:
原文地址:http://www.cnblogs.com/chenchengxun/p/4845058.html