# UPC-自习课 模拟题

5
...
XX.
..O
XOX
XXO
OXO
.O.
XO.
.O.
XOX
OX.
X.O
XXX
OOO
...


O's turn
Draw
Illegal Situation
X wins
Illegal Situation


X和O的数量之间的差不能超过两个，并且先手X的数量一定要大于等于O的数量，并且两人不能同时取得游戏的胜利 这是判断不合法的情况

X和O赢得比赛的时候的情形比较好判断，这里不再赘述

Code:

#include <bits/stdc++.h>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
const ll inf = 1e15;
const ll INF = 0x3f3f3f3f;
const int maxn = 2e6 + 7;
const int mod = 998244353;
#define start int wuyt()
#define end return 0
#define pi 3.14159265358979323846
ll maxx=-1;
ll minn=inf;
ll num[maxn];
int ct;
///ll a[maxn];
ll num2[maxn];
ll res,ans;
priority_queue <int ,vector<int> ,greater<int> > xiaogen;
priority_queue <int ,vector<int> ,less<int> > dagen;
char ss[5][5];
bool x_win(){
if(ss[1][1]=='X'&&ss[1][2]=='X'&&ss[1][3]=='X') return true;
if(ss[2][1]=='X'&&ss[2][2]=='X'&&ss[2][3]=='X') return true;
if(ss[3][1]=='X'&&ss[3][2]=='X'&&ss[3][3]=='X') return true;

if(ss[1][1]=='X'&&ss[2][1]=='X'&&ss[3][1]=='X') return true;
if(ss[1][2]=='X'&&ss[2][2]=='X'&&ss[3][2]=='X') return true;
if(ss[1][3]=='X'&&ss[2][3]=='X'&&ss[3][3]=='X') return true;

if(ss[1][1]=='X'&&ss[2][2]=='X'&&ss[3][3]=='X') return true;
if(ss[3][1]=='X'&&ss[2][2]=='X'&&ss[1][3]=='X') return true;

return false;
}
bool o_win(){
if(ss[1][1]=='O'&&ss[1][2]=='O'&&ss[1][3]=='O') return true;
if(ss[2][1]=='O'&&ss[2][2]=='O'&&ss[2][3]=='O') return true;
if(ss[3][1]=='O'&&ss[3][2]=='O'&&ss[3][3]=='O') return true;

if(ss[1][1]=='O'&&ss[2][1]=='O'&&ss[3][1]=='O') return true;
if(ss[1][2]=='O'&&ss[2][2]=='O'&&ss[3][2]=='O') return true;
if(ss[1][3]=='O'&&ss[2][3]=='O'&&ss[3][3]=='O') return true;

if(ss[1][1]=='O'&&ss[2][2]=='O'&&ss[3][3]=='O') return true;
if(ss[3][1]=='O'&&ss[2][2]=='O'&&ss[1][3]=='O') return true;

return false;
}
int main()
{
while(n--){
int cntx=0,cnto=0;
for(int i=1;i<=3;i++)
cin>>ss[i]+1;

/// 统计数量
for(int i=1;i<=3;i++)
{
for(int j=1;j<=3;j++)
{
if(ss[i][j]=='X') cntx++;
else if(ss[i][j]=='O') cnto++;
}
}
///差值>=2 不合法 数量上
if(abs(cntx-cnto)>=2||cnto>cntx||o_win()&&x_win()){
printf("Illegal Situation\n");
continue;
}
else {
if(cntx==cnto&&cntx==0) {
printf("X's turn\n");
continue;
}
if(cntx==5&&cnto==4&&!o_win()&&!x_win()){
printf("Draw\n");///平局ok
continue;
}
if(o_win()&&!x_win()&&cntx==cnto){
printf("O wins\n");
continue;
}
if(!o_win()&&x_win()&&cntx==cnto+1){
printf("X wins\n");
continue;
}
if(!o_win()&&!x_win()&&abs(cnto-cntx)<=1){
if(cntx==cnto){
printf("X's turn\n");
continue;
}
else if(cnto+1==cntx){
printf("O's turn\n");
continue;
}
}
printf("Illegal Situation\n");
}

}
return 0;
}
/**

5
...
XX.
..O
XOX
XXO
OXO
.O.
XO.
.O.
XOX
OX.
X.O
XXX
OOO
...

**/



04-07 216

04-10 95

10-12 99

05-30 91

04-13 125

08-23 105

04-06 122

07-16 2688

#### 条形码原理之UPC-A/E

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。