当前位置: 代码迷 >> 综合 >> poj 2361 Tic Tac Toe 五子棋模拟
  详细解决方案

poj 2361 Tic Tac Toe 五子棋模拟

热度:83   发布时间:2024-01-19 05:29:14.0
//poj 2361
//sep9
//与poj3075的区别是在游戏中的状态也合法
#include <iostream>
#include <algorithm>
using namespace std;
int way[8][3]={{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}
};
char s[16];bool check(char c)
{for(int i=0;i<8;++i){int j;for(j=0;j<3;++j)if(s[way[i][j]]!=c)break;if(j==3)return true;		}return false;	
}int main()
{int x,o,cases;scanf("%d",&cases);while(cases--){scanf("%s%s%s",s,&s[3],&s[6]);x=count(s,s+9,'X');o=count(s,s+9,'O');if(x<o||o+1<x)	puts("no");else if(x>o&&check('X')&&!check('O')) puts("yes");else if(o==x&&!check('X')&&check('O')) puts("yes");else if(!check('X')&&!check('O')) puts("yes");else puts("no");}return 0;	
} 

  相关解决方案