hdu4414 字符串 模拟

 
#include
#include
#include
#define M 55
using namespace std;
char map [M][M];
int  find (int x,int y)
{
    int a,b,c,d,i;
    a=b=c=d=0;
    for(i=1;map[x-i][y]=='#';i++)
    {
        if(map[x-i][y+1]=='#'||map[x-i][y-1]=='#')
        return 0;
         a=i;
    }
    for(i=1;map[x+i][y]=='#';i++)     
    {
        if(map[x+i][y+1]=='#'||map[x+i][y-1]=='#')
        return 0;
        b=i;
    }
    for(i=1;map[x][y-i]=='#';i++)
    {
        if(map[x+1][y-i]=='#'||map[x-1][y-i]=='#')
        return 0;
        c=i;
    }
    for(i=1;map[x][y+i]=='#';i++)
    {
        if(map[x+1][y+i]=='#'||map[x-1][y+i]=='#')
        return 0;
        d=i;
    }
    if(a==b&&a==c&&a==d&&a)
    return 1;
    else
    return 0;
}
int main ()
{
    int n,i,j,sum;
    while (~scanf("%d",&n),n)
    {
        sum=0;
        memset(map,0,sizeof(map));
        for(i=1;i<=n;i++)
        {
            scanf("%s",map[i]+1);
        }
        for(i=0;i<=n+1;i++)
  map[0][i]=map[i][0]=map[n+1][i]=map[i][n+1]='o';
       for(i=1;i<=n;i++)
       for(j=1;j<=n;j++)
       {
           if(map[i][j]=='#')
           sum+=find(i,j);
       }
        printf("%d\n",sum);
    }
    return 0;
}


你可能感兴趣的:(hdu4414 字符串 模拟)