#include<stdio.h>
#include<string.h>
#include<ctype.h>
main()
{
long int a,b,cnt=1;
while(scanf("%ld%ld",&a,&b)!=EOF)
{
char s[200][200]={0};
long int i,j,k,count;
if(a==0 && b==0)
break;
else
{
for(i=0;i<a;i++)
{
scanf("%s",s[i]);
}
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
if(s[i][j]=='*')
continue;
else
s[i][j]='0';
}
}
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
if(s[i][j]=='*')
{
if(isdigit(s[i-1][j-1]))
s[i-1][j-1]=s[i-1][j-1]+1;
if(isdigit(s[i-1][j]))
s[i-1][j]=s[i-1][j]+1;
if(isdigit(s[i-1][j+1]))
s[i-1][j+1]=s[i-1][j+1]+1;
if(isdigit(s[i][j-1]))
s[i][j-1]=s[i][j-1]+1;
if(isdigit(s[i][j+1]))
s[i][j+1]=s[i][j+1]+1;
if(isdigit(s[i+1][j-1]))
s[i+1][j-1]=s[i+1][j-1]+1;
if(isdigit(s[i+1][j]))
s[i+1][j]=s[i+1][j]+1;
if(isdigit(s[i+1][j+1]))
s[i+1][j+1]=s[i+1][j+1]+1;
}
}
}
if(cnt>1)
printf("\n");
printf("Field #%ld:\n",cnt);
cnt++;
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
printf("%c",s[i][j]);
}
printf("\n");
}
}
}
}
#include<string.h>
#include<ctype.h>
main()
{
long int a,b,cnt=1;
while(scanf("%ld%ld",&a,&b)!=EOF)
{
char s[200][200]={0};
long int i,j,k,count;
if(a==0 && b==0)
break;
else
{
for(i=0;i<a;i++)
{
scanf("%s",s[i]);
}
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
if(s[i][j]=='*')
continue;
else
s[i][j]='0';
}
}
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
if(s[i][j]=='*')
{
if(isdigit(s[i-1][j-1]))
s[i-1][j-1]=s[i-1][j-1]+1;
if(isdigit(s[i-1][j]))
s[i-1][j]=s[i-1][j]+1;
if(isdigit(s[i-1][j+1]))
s[i-1][j+1]=s[i-1][j+1]+1;
if(isdigit(s[i][j-1]))
s[i][j-1]=s[i][j-1]+1;
if(isdigit(s[i][j+1]))
s[i][j+1]=s[i][j+1]+1;
if(isdigit(s[i+1][j-1]))
s[i+1][j-1]=s[i+1][j-1]+1;
if(isdigit(s[i+1][j]))
s[i+1][j]=s[i+1][j]+1;
if(isdigit(s[i+1][j+1]))
s[i+1][j+1]=s[i+1][j+1]+1;
}
}
}
if(cnt>1)
printf("\n");
printf("Field #%ld:\n",cnt);
cnt++;
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
printf("%c",s[i][j]);
}
printf("\n");
}
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন