标签:io ar os sp for bs amp as nbsp
题目:给你一个井字棋的状态,判断是否合法。
分析:枚举。直接枚举多有情况判断即可。
合法状态有三种情况:(X先下子)
1.X赢,则O不能赢,且X比O多一子;
2.O赢,则X不能赢,且O和X子一样多;
3.没人赢,此时O的子和可能和X一样多,也可能少一个。
说明:简单题(⊙_⊙)。
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; char maps[4][4]; int win(char c) { if (maps[0][0] == c && maps[0][1] == c && maps[0][2] == c) return 1; if (maps[0][0] == c && maps[1][0] == c && maps[2][0] == c) return 1; if (maps[0][0] == c && maps[1][1] == c && maps[2][2] == c) return 1; if (maps[1][0] == c && maps[1][1] == c && maps[1][2] == c) return 1; if (maps[2][0] == c && maps[2][1] == c && maps[2][2] == c) return 1; if (maps[0][1] == c && maps[1][1] == c && maps[2][1] == c) return 1; if (maps[0][2] == c && maps[1][2] == c && maps[2][2] == c) return 1; if (maps[0][2] == c && maps[1][1] == c && maps[2][0] == c) return 1; return 0; } int main() { int n; while (~scanf("%d",&n)) while (n --) { for (int i = 0 ; i < 3 ; ++ i) scanf("%s",maps[i]); int X_count = 0,O_count = 0; for (int i = 0 ; i < 3 ; ++ i) for (int j = 0 ; j < 3 ; ++ j) { X_count += (maps[i][j] == 'X'); O_count += (maps[i][j] == 'O'); } int X_win = win('X'),O_win = win('O'); if (X_count == O_count+1 && X_win && !O_win || X_count == O_count && O_win && !X_win || (X_count == O_count || X_count == O_count+1) && !X_win && !O_win) printf("yes\n"); else printf("no\n"); } return 0; }
标签:io ar os sp for bs amp as nbsp
原文地址:http://blog.csdn.net/mobius_strip/article/details/41172429