output
standard output
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it’s Alice’s turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.
Input
You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters ‘X’ being a cross, letters ‘O’ being a nought and ‘.’ being an empty cell. The number of ‘X’ cells is equal to the number of ‘O’ cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
Output
Print ‘YES’ if it’s possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print ‘NO’.
Examples
input
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........
output
YES
input
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
output
NO
简单模拟题,因为数据只有10*10 比较小,所以我们直接枚举每一个‘.’位置,如果在这个位置填上’X’能赢的话就输出YES 否则输出NO
#include <iostream>
#include <cstring>
#include <stack>
#include <cstdio>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
const double eps=1e-8;
const double PI=acos(-1.0);
using namespace std;
char a[20][20];
int main()
{
for(int i=0; i<10; i++)
{
scanf("%s",a[i]);
}
int flag=0;
for(int i=0; i<10; i++)
{
if(flag)
break;
for(int j=0; j<10; j++)
{
int cou=0,cou1=0,cou2=0,cou3=0;//记录左边,右边,主对角,副对角上的X数量
if(a[i][j]=='.')
{
// while(i>=0&&j>=0&&i<10&&j<10)
int l=j,r=j,l1=i,r1=j,l2=i,r2=j;
int l3=i,r3=j,l4=i,r4=j,l5=i,r5=i;//8个并列while去找对应方向的"X",
while((l--)>=0&&a[i][l]=='X') cou++;
while((r++)<10&&a[i][r]=='X') cou++;
while((l1++)<10&&(r1++)<10&&a[l1][r1]=='X') cou1++;
while((l2--)>=0&&(r2--)>=0&&a[l2][r2]=='X') cou1++;
while((l3--)>=0&&(r3++)<10&&a[l3][r3]=='X') cou2++;
while((l4++)<10&&(r4--)>=0&&a[l4][r4]=='X') cou2++;
while((l5--)>=0&&a[l5][j]=='X') cou3++;
while((r5++)<10&&a[r5][j]=='X') cou3++;
if(cou>=4||cou1>=4||cou2>=4||cou3>=4)//如果有任意一个方向的数量符合要求就标记输出
{
//cout<<cou3<<" "<<j<<endl;
printf("YES\n");
flag=1;
break;
}
}
}
}
if(!flag)
printf("NO\n");