思路: 对放置有x的地方进行上·下·左·右·左上·左下·右上·右下搜索。
分为四次,横向,纵向,左斜对角线,右斜对角线
#include<stdio.h>
char map[12][12];
int main()
{
int i,j,k,q;
for(i=0; i<10; i++)
scanf("%s",map[i]);
for(i=0; i<10; i++)
for(j=0; j<10; j++)
{
if(map[i][j]=='.')
{
int s=1; //下面两个for循环代表竖着的方向寻找五子棋
for(int k=j+1; k<10; k++)//向下搜索
{
if(map[i][k]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
for(int k=j-1; k>=0; k--) //向上搜索
{
if(map[i][k]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
s=1; //下面两个for循环代表横着的方向寻找五子棋
for(int k=i+1; k<10; k++) //向右搜索
{
if(map[k][j]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
for(int k=i-1; k>=0; k--) //向左搜索
{
if(map[k][j]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
s=1; //下面两个for循环代表\(对角线)的方向寻找五子棋
for(k=i-1,q=j-1; q>=0,k>=0; q--,k--) //向左上搜索
{
if(map[k][q]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
for(k=i+1,q=j+1; q<10,k<10; q++,k++)//向右下搜索
{
if(map[k][q]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
s=1; //下面两个for循环代表/(对角线)的方向寻找五子棋
for(k=i+1,q=j-1; q>=0,k<10; q--,k++) //向右上搜索
{
if(map[k][q]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
for(k=i-1,q=j+1; q<10,k>=0; q++,k--)//向左下搜索
{
if(map[k][q]=='X')
{
s++;
if(s==5)
{
printf("YES\n");
return 0;
}
}
else break;
}
}
}
printf("NO\n");
return 0;
}