本帖最後由 蔡沛倢 於 2024-8-30 19:03 編輯
- #include<bits/stdc++.h>
- using namespace std;
- int b,c;
- int main()
- {
- cin>>b>>c;
- int a[b][c];
- for(int i=0;i<b;i++)
- {
- for(int j=0;j<c;j++)
- {
- cin>>a[i][j];
- }
- }
- for(int i=0;i<b;i++)
- {
- for(int j=0;j<c;j++)
- {
- if(a[i][j]==0)
- {
- cout<<" ";
- }
- else
- {
- 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)
- {
- cout<<'*';
- }
- else
- {
- cout<<' ';
- }
- }
- }
- cout<<endl;
- }
- return 0;
- }
複製代碼 |