Problem Type: Game
#include<stdio.h>
#include<string.h>
#define max 201
int main()
{
char mat[max][max],mat1[max][max];
int i,j,n,m,x,cou=0;
while(scanf("%d %d",&n,&m)==2)
{
if(n==0 && m==0)
break;
if(cou!=0)
{
printf("\n");
}
cou++;
getchar();
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
mat1[i][j]='0';
}
}
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
scanf(" %c",&mat[i][j]);
}
}
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
if(mat[i][j]=='*')
{
mat1[i][j]='*';
if(mat[i-1][j-1]!='*')
{
x=mat1[i-1][j-1]-'0';
x=x+1;
mat1[i-1][j-1]=x+48;
}
if(mat[i-1][j]!='*')
{
x=mat1[i-1][j]-'0';
x=x+1;
mat1[i-1][j]=x+48;
}
if(mat[i-1][j+1]!='*')
{
x=mat1[i-1][j+1]-'0';
x=x+1;
mat1[i-1][j+1]=x+48;
}
if(mat[i][j-1]!='*')
{
x=mat1[i][j-1]-'0';
x=x+1;
mat1[i][j-1]=x+48;
}
if(mat[i][j+1]!='*')
{
x=mat1[i][j+1]-'0';
x=x+1;
mat1[i][j+1]=x+48;
}
if(mat[i+1][j-1]!='*')
{
x=mat1[i+1][j-1]-'0';
x=x+1;
mat1[i+1][j-1]=x+48;
}
if(mat[i+1][j]!='*')
{
x=mat1[i+1][j]-'0';
x=x+1;
mat1[i+1][j]=x+48;
}
if(mat[i+1][j+1]!='*')
{
x=mat1[i+1][j+1]-'0';
x=x+1;
mat1[i+1][j+1]=x+48;
}
}
}
}
printf("Field #%d:\n",cou);
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
printf("%c",mat1[i][j]);
}
printf("\n");
}
memset(mat,'\0',sizeof(mat));
}
}
#include<stdio.h>
#include<string.h>
#define max 201
int main()
{
char mat[max][max],mat1[max][max];
int i,j,n,m,x,cou=0;
while(scanf("%d %d",&n,&m)==2)
{
if(n==0 && m==0)
break;
if(cou!=0)
{
printf("\n");
}
cou++;
getchar();
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
mat1[i][j]='0';
}
}
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
scanf(" %c",&mat[i][j]);
}
}
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
if(mat[i][j]=='*')
{
mat1[i][j]='*';
if(mat[i-1][j-1]!='*')
{
x=mat1[i-1][j-1]-'0';
x=x+1;
mat1[i-1][j-1]=x+48;
}
if(mat[i-1][j]!='*')
{
x=mat1[i-1][j]-'0';
x=x+1;
mat1[i-1][j]=x+48;
}
if(mat[i-1][j+1]!='*')
{
x=mat1[i-1][j+1]-'0';
x=x+1;
mat1[i-1][j+1]=x+48;
}
if(mat[i][j-1]!='*')
{
x=mat1[i][j-1]-'0';
x=x+1;
mat1[i][j-1]=x+48;
}
if(mat[i][j+1]!='*')
{
x=mat1[i][j+1]-'0';
x=x+1;
mat1[i][j+1]=x+48;
}
if(mat[i+1][j-1]!='*')
{
x=mat1[i+1][j-1]-'0';
x=x+1;
mat1[i+1][j-1]=x+48;
}
if(mat[i+1][j]!='*')
{
x=mat1[i+1][j]-'0';
x=x+1;
mat1[i+1][j]=x+48;
}
if(mat[i+1][j+1]!='*')
{
x=mat1[i+1][j+1]-'0';
x=x+1;
mat1[i+1][j+1]=x+48;
}
}
}
}
printf("Field #%d:\n",cou);
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
printf("%c",mat1[i][j]);
}
printf("\n");
}
memset(mat,'\0',sizeof(mat));
}
}
No comments:
Post a Comment