#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, m, i, j, k;
while(cin >> m)
{
for(k=1; k<=m; k++)
{
cin >> n;
char ch[n][n];
char an[n][n];
char rt[n][n];
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin >> ch[i][j];
}
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin >> an[i][j];
}
}
int f = 0;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(an[i][j] == 'x')
{
if(ch[i][j] == '*')
{
rt[i][j] == '*';
f = 1;
}
else
{
int c = 0;
if(i-1 >=0 && j-1>=0 && ch[i-1][j-1] == '*')
{
c++;
}
if(i-1>=0 && ch[i-1][j] == '*')
{
c++;
}
if(i-1 >= 0 && j+1<n && ch[i-1][j+1] == '*')
{
c++;
}
if(j-1>=0 && ch[i][j-1] == '*')
{
c++;
}
if(j+1<n && ch[i][j+1] == '*')
{
c++;
}
if(i+1<n && ch[i+1][j] == '*')
{
c++;
}
if(i+1<n && j-1>=0 && ch[i+1][j-1] == '*')
{
c++;
}
if(i+1<n && j+1<n && ch[i+1][j+1] == '*' )
{
c++;
}
rt[i][j] = c + '0';
}
}
else
rt[i][j] = an[i][j];
}
}
if(f == 1)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(ch[i][j] == '*')
rt[i][j] = ch[i][j];
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout << rt[i][j];
}
cout << endl;
}
if(k<m)
cout << endl;
}
}
return 0;
}
using namespace std;
int main()
{
int n, m, i, j, k;
while(cin >> m)
{
for(k=1; k<=m; k++)
{
cin >> n;
char ch[n][n];
char an[n][n];
char rt[n][n];
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin >> ch[i][j];
}
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
cin >> an[i][j];
}
}
int f = 0;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(an[i][j] == 'x')
{
if(ch[i][j] == '*')
{
rt[i][j] == '*';
f = 1;
}
else
{
int c = 0;
if(i-1 >=0 && j-1>=0 && ch[i-1][j-1] == '*')
{
c++;
}
if(i-1>=0 && ch[i-1][j] == '*')
{
c++;
}
if(i-1 >= 0 && j+1<n && ch[i-1][j+1] == '*')
{
c++;
}
if(j-1>=0 && ch[i][j-1] == '*')
{
c++;
}
if(j+1<n && ch[i][j+1] == '*')
{
c++;
}
if(i+1<n && ch[i+1][j] == '*')
{
c++;
}
if(i+1<n && j-1>=0 && ch[i+1][j-1] == '*')
{
c++;
}
if(i+1<n && j+1<n && ch[i+1][j+1] == '*' )
{
c++;
}
rt[i][j] = c + '0';
}
}
else
rt[i][j] = an[i][j];
}
}
if(f == 1)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(ch[i][j] == '*')
rt[i][j] = ch[i][j];
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout << rt[i][j];
}
cout << endl;
}
if(k<m)
cout << endl;
}
}
return 0;
}
Comments
Post a Comment