2020 BIT冬训-模拟与暴力 L - Five-In-a-Row CodeForces - 825B

Problem Description

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
没啥可说的……循环减少码量就行了
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
char qi[15][15];
int sum,flag;
int main(){
    for(int i=0;i<10;i++)
        scanf("%s",qi[i]);
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(qi[i][j]=='.'){
                sum=0;
                for(int k=i-1;k>=0;k--)//向左找
                    if(qi[k][j]=='X')
                        sum++;
                    else
                        break;
                for(int k=i+1;k<10;k++)//向右找
                    if(qi[k][j]=='X')
                        sum++;
                    else
                        break;    
                if(sum>=4)
                    flag=1;
                if(flag)
                    break;
                sum=0; 
                for(int k=j-1;k>=0;k--)//向上找
                    if(qi[i][k]=='X')
                        sum++;
                    else
                        break;
                for(int k=j+1;k<10;k++)//向下找
                    if(qi[i][k]=='X')
                        sum++;
                    else
                        break;
                if(sum>=4)
                    flag=1;
                if(flag)
                    break;
                sum=0;
                for(int k=i-1,l=j-1;k>=0,l>=0;k--,l--)//斜向左上找
                    if(qi[k][l]=='X')
                        sum++;
                    else
                        break;
                for(int k=i+1,l=j+1;k<10,l<10;k++,l++)//斜向右下找
                    if(qi[k][l]=='X')
                        sum++;
                    else
                        break;
                if(sum>=4)
                    flag=1;
                if(flag)
                    break;
                sum=0;
                for(int k=i+1,l=j-1;k<10,l>=0;k++,l--)//斜向右上找
                    if(qi[k][l]=='X')
                        sum++;
                    else
                        break;
                for(int k=i-1,l=j+1;k>=0,l<10;k--,l++)//斜向左下找
                    if(qi[k][l]=='X')
                        sum++;
                    else
                        break;
                if(sum>=4)
                    flag=1;
                if(flag)
                    break;
                sum=0;
            }
            if(flag)
                break;
        }
    }
    if(flag)
        printf("YES");
    else
        printf("NO");
}

 




上一篇:阿里云企业实名认证怎么操作-如何进行企业实名认证


下一篇:变量,变量赋值