返回列表 發帖
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,m;
  6.     cin>>n>>m;
  7.     int mat[n][m];
  8.     for(int i=0;i<n;i++)
  9.         for(int j=0;j<m;j++)
  10.             cin>>mat[i][j];
  11.     for(int i=0;i<n;i++){
  12.         for(int j=0;j<m;j++){
  13.             if(mat[i][j]==0)
  14.                 cout<<' ';
  15.             else if(i==0||i==n-1||j==0||j==m-1||mat[i-1][j]==0||mat[i+1][j]==0||mat[i][j-1]==0||mat[i][j+1]==0)
  16.                 cout<<'*';
  17.             else
  18.                 cout<<' ';
  19.         }
  20.         cout<<endl;
  21.     }
  22.     return 0;
  23. }
複製代碼

TOP

返回列表