Poj Solution 2612

http://poj.org/problem?id=2612

#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
char mine[15][15];
char touch[15][15];
char board[15][15];
int i,j,n,num=0;
bool flag=false;
scanf("%d",&n);
for(i=0;i<n;i++)
   scanf("%s",mine[i]);
for(i=0;i<n;i++)
   scanf("%s",touch[i]);
for(i=0;i<n;i++)
   for(j=0;j<n;j++)
   {
    if(touch[i][j]=='x')
    {
     if(mine[i][j]=='*')
     {
      flag=true;
      board[i][j]='*';
     }
     else if(mine[i][j]=='.')
     {
      if((j-1)>=0&&mine[i][j-1]=='*')
       num++;
      if((j+1)<n&&mine[i][j+1]=='*')
       num++;
      if(i-1>=0)
      {
       if((j-1)>=0&&mine[i-1][j-1]=='*')
        num++;
       if(mine[i-1][j]=='*')
        num++;
       if((j+1)<n&&mine[i-1][j+1]=='*')
        num++;
      }
      if(i+1<n)
      {
       if((j-1)>=0&&mine[i+1][j-1]=='*')
        num++;
       if(mine[i+1][j]=='*')
        num++;
       if((j+1)<n&&mine[i+1][j+1]=='*')
        num++;
      }

      board[i][j]=num+48;
      num=0;
     }
    }
    else if(touch[i][j]=='.')
     board[i][j]='.';
   }
if(flag)
{
   for(i=0;i<n;i++)
    for(j=0;j<n;j++)
     if(mine[i][j]=='*')
      board[i][j]='*';
}
for(i=0;i<n;i++)
{
   for(j=0;j<n;j++)
    printf("%c",board[i][j]);
   printf("n");
}
system("pause");
return 0;
}
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *