@[wdfamz](/space/show?uid=231462) 请在“ ``` ”后加上“cpp”,而不是“pascal”
by YosemiteHe @ 2019-08-23 18:23:34
@[wdfamz](/space/show?uid=231462) so?
by ieeqwq @ 2019-08-23 18:27:46
```
```cpp
#include<iostream>
using namespace std;
int n,a[35][35],b[35][35];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
b[i][j]=a[i][j];
if((i==1||i==n||j==1||j==n)&&a[i][j]==0)
{
a[i][j]=3;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]==0&&(a[i][j+1]==3||a[i+1][j]==3||a[i-1][j]==3||a[i][j-1]==3))
{
a[i][j]=3;
}
}
}
for(int i=n;i>=1;i--)
{
for(int j=n;j>=1;j--)
{
if(a[i][j]==0&&(a[i][j+1]==3||a[i+1][j]==3||a[i-1][j]==3||a[i][j-1]==3))
{
a[i][j]=3;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]==0)
{
cout<<2<<" ";
}
else
{
cout<<b[i][j]<<" ";
}
}
cout<<endl;
}
return 0;
}
```}
```
by jijidawang @ 2020-01-08 20:30:39