返回列表 發帖
本帖最後由 蔡沛倢 於 2024-8-30 19:03 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int b,c;

  4. int main()
  5. {
  6.     cin>>b>>c;
  7.     int a[b][c];
  8.     for(int i=0;i<b;i++)
  9.     {
  10.         for(int j=0;j<c;j++)
  11.         {
  12.             cin>>a[i][j];
  13.         }
  14.     }
  15.     for(int i=0;i<b;i++)
  16.     {
  17.         for(int j=0;j<c;j++)
  18.         {
  19.             if(a[i][j]==0)
  20.             {
  21.                 cout<<" ";
  22.             }
  23.             else
  24.             {
  25.                  if(i==0 || i==b-1 || j==0 || j==c-1 || a[i-1][j]==0 || a[i+1][j]==0 || a[i][j-1]==0 || a[i][j+1]==0)
  26.                  {
  27.                     cout<<'*';
  28.                  }
  29.                  else
  30.                  {
  31.                     cout<<' ';
  32.                  }

  33.             }

  34.         }
  35.         cout<<endl;
  36.     }
  37.     return 0;
  38. }
複製代碼

TOP

返回列表