註冊
登錄
論壇
搜索
幫助
導航
私人消息 (0)
公共消息 (0)
系統消息 (0)
好友消息 (0)
帖子消息 (0)
種子論壇 | 高雄市資訊培育協會學員討論區
»
程式解題我最行(週五19:00-21:00)
» 510 星號輸出
返回列表
發帖
發短消息
加為好友
陳曜誌
當前離線
UID
69297
帖子
153
精華
0
積分
0
閱讀權限
100
在線時間
82 小時
註冊時間
2024-6-26
最後登錄
2024-9-20
版主
1
#
跳轉到
»
倒序看帖
打印
字體大小:
t
T
陳曜誌
發表於 2024-8-22 03:34
|
只看該作者
510 星號輸出
1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。
2. 設計說明:
請撰寫一程式,讓使用者輸入兩個正整數n、m,代表n*m矩陣。在矩陣內各別輸入0或1,若矩陣最外圍的輸入為1,則輸出符號「*」;若1的上下左右有其一為0,亦輸出符號「*」;其餘則以半形空格表示,最後將結果輸出在畫面上。
提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。
3. 輸入輸出:
輸入說明
兩個正整數n、m及n*m矩陣中的所有元素(只有0和1)
輸出說明
轉換後的結果
範例輸入
4 7
0 0 0 1 0 0 0
0 0 1 1 1 0 0
0 1 1 1 1 1 0
1 1 1 1 1 1 1
範例輸出
*
* *
* *
*******
程式輸出擷圖
下圖中的 黃色點 為 空格
本帖隱藏的內容需要回復才可以瀏覽
收藏
分享
發短消息
加為好友
田家齊
當前離線
UID
68816
帖子
287
精華
0
積分
0
閱讀權限
10
在線時間
92 小時
註冊時間
2021-8-12
最後登錄
2024-9-13
新手上路
2
#
田家齊
發表於 2024-8-23 20:55
|
只看該作者
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
cin>>a>>b;
int x[a][b];
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
cin>>x[i][j];
}
}
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
if(x[i][j]==0)
{
cout<<" ";
}else if(i==0 or i==a-1 or j==0 or j==b-1 or x[i+1][j]==0 or x[i-1][j]==0 or x[i][j+1]==0 or x[i][j-1]==0)
{
cout<<"*";
}else
{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
發短消息
加為好友
黃翊豪
當前離線
UID
69236
帖子
150
精華
0
積分
0
閱讀權限
10
在線時間
36 小時
註冊時間
2024-1-18
最後登錄
2024-9-19
新手上路
3
#
黃翊豪
發表於 2024-8-23 20:58
|
只看該作者
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
cin>>n>>m;
int data[n][m];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>data[i][j];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(data[i][j]==0)
cout<<' ';
else
{
if(i==0 || i==n-1 || j==0 || j==m-1 || data[i-1][j]==0 || data[i+1][j]==0 || data[i][j-1]==0 || data[i][j+1]==0)
cout<<'*';
else
cout<<' ';
}
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
發短消息
加為好友
得銓
當前離線
UID
69166
帖子
136
精華
0
積分
0
閱讀權限
10
在線時間
54 小時
註冊時間
2023-7-21
最後登錄
2024-9-7
新手上路
4
#
得銓
發表於 2024-8-23 20:58
|
只看該作者
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int data[n][m];
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
cin>>data[i][j];
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
if(data[i][j]==0)
cout<<' ';
else
{
if(i==0 or i==n-1 or j==0 or j==m-1 or data[i-1][j]==0 or data[i+1][j]==0 or data[i][j-1]==0 or data[i][j+1]==0)
cout<<'*';
else
cout<<' ';
}
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
發短消息
加為好友
何權晉
當前離線
UID
69053
帖子
199
精華
0
積分
0
閱讀權限
10
在線時間
60 小時
註冊時間
2022-11-15
最後登錄
2024-9-13
新手上路
5
#
何權晉
發表於 2024-8-23 21:04
|
只看該作者
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int data[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>data[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(data[i][j]==0)
{
cout<<' ';
}
else{
if(i==0 || i==n-1 || j==0 || j==m-1 || data[i-1][j]==0 || data[i][j-1]==0 || data[i+1][j]==0 || data[i][j+1])
cout<<'*';
else
cout<<' ';
}
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
發短消息
加為好友
蔡沛倢
當前離線
UID
69006
帖子
203
精華
0
積分
0
閱讀權限
10
在線時間
69 小時
註冊時間
2022-10-28
最後登錄
2024-9-13
新手上路
6
#
蔡沛倢
發表於 2024-8-23 21:04
|
只看該作者
本帖最後由 蔡沛倢 於 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;
}
複製代碼
TOP
發短消息
加為好友
呂宗晉
當前離線
UID
69052
帖子
313
精華
0
積分
0
閱讀權限
10
在線時間
96 小時
註冊時間
2022-11-9
最後登錄
2024-9-6
新手上路
7
#
呂宗晉
發表於 2024-8-27 20:31
|
只看該作者
#include<bits/stdc++.h>
using namespace std;
int n, m;
int main()
{
cin>>n>>m;
int data[n][m];
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
cin>>data[i][j];
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
if(data[i][j]==0)
cout<<' ';
else
{
if(i==0 || i==n-1 || j==0 || j==m-1 || data[i-1][j]==0 || data[i+1][j]==0 || data[i][j-1]==0 || data[i][j+1]==0)
cout<<'*';
else
cout<<' ';
}
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
發短消息
加為好友
郭又瑄
當前離線
UID
68831
帖子
315
精華
0
積分
0
閱讀權限
10
在線時間
76 小時
註冊時間
2021-10-1
最後登錄
2024-9-16
新手上路
8
#
郭又瑄
發表於 2024-8-30 18:52
|
只看該作者
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
cin>>a>>b;
int x[a][b];
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
cin>>x[i][j];
}
}
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
if(x[i][j]==0)
{
cout<<" ";
}else if(i==0 or i==a-1 or j==0 or j==b-1 or x[i+1][j]==0 or x[i-1][j]==0 or x[i][j+1]==0 or x[i][j-1]==0)
{
cout<<"*";
}else
{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
發短消息
加為好友
聿均
當前離線
UID
69113
帖子
78
精華
0
積分
0
閱讀權限
10
在線時間
16 小時
註冊時間
2023-6-2
最後登錄
2024-9-13
新手上路
9
#
聿均
發表於 2024-8-30 20:14
|
只看該作者
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int mat[n][m];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>mat[i][j];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mat[i][j]==0)
cout<<' ';
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)
cout<<'*';
else
cout<<' ';
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
發短消息
加為好友
邱品惟
當前離線
UID
69086
帖子
188
精華
0
積分
0
閱讀權限
10
在線時間
44 小時
註冊時間
2023-3-1
最後登錄
2024-9-18
新手上路
10
#
邱品惟
發表於 2024-9-6 18:22
|
只看該作者
#include<bits/stdc++.h>
using namespace std;
int n, m;
int main()
{
cin>>n>>m;
int data[n][m];
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
cin>>data[i][j];
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
if(data[i][j]==0)
cout<<' ';
else
{
if(i==0 || i==n-1 || j==0 || j==m-1 || data[i-1][j]==0 || data[i+1][j]==0 || data[i][j-1]==0 || data[i][j+1]==0)
cout<<'*';
else
cout<<' ';
}
}
cout<<endl;
}
return 0;
}
複製代碼
TOP
返回列表
谷哥人營隊
113Scratch夏令營
113年APCS冬令營
113年Scratch冬令營
113年Python研習冬令營
113年Python證照特訓營(一)
113年谷哥人程式體驗營
113年國三專班
113年Python研習夏令營
113年Python證照特訓營(二)
113年程式夏令營(一)(二)
113年APCS夏令營(一)(二)
112年國三專班
112APCS夏令營(一)(二)
112App快速開發夏令營
C語言 / C++ (特別輔導)
C++證照
C#
家教特輔
C語言特輔/證照(家教)
C++證照
C#
HTML5+CSS+JavaScript+PHP+MySQL
Java 家教 (王捷恩)
113新版塊名稱
快樂學 Scratch
Python 家教 (王捷恩 康恒睿)
Python 特別輔導 (家教)
快樂 C++ (家教)
我愛 Java (家教)
程式解題我最行 (家教)
程式常態班
C++ 新生挑戰區
考照心得分享
快樂 C++11307週五19:00
快樂 C++11303 (週六15:40-17:40) 3F
程式解題我最行 (週六15:30-17:30) 3F
快樂 C++ (週六13:30-15:30) 3F
快樂 C++ (週六19:00-21:00) 3F
程式解題我最行 (週六10:00-12:00) 3F
快樂學 Scratch
程式解題我最行(週五19:00-21:00)
快樂 C++ (週六13:30-15:30) 3F
程式解題我最行(週三19:15-21:15)
快樂 C++11207週六10
快樂 C++11208週六19:00
程式解題我最行 (週五19:00-21:00) 3F
快樂 C++ (週六15:30-17:30) 3F
程式解題我最行 (週六19:00-21:00) 3F
程式解題我最行 (週四19:10-21:10)
產投職訓
結訓課程 (產投職訓)
Php & MySQL old
Illustrator old
Dreamweaver old
Android手機程式開發班
PHP & MySQL電子商務互動式網站實作班 (102下)
PHP & MySQL (102上)
PHP & MySQL電子商務互動式網站實作班
Photoshop數位影像設計初階
Flash創意廣告動畫初階
行銷短片視訊剪輯
數位商業攝影實務班
PHP & MySQL電子商務系統開發實務初階班
電子商務系統開發實務中階班
Server基礎架設&動態網頁設計初階班
Java視窗應用程式設計與遊戲開發班
Illustrator時尚插畫創作設計初階班
102上Php & MySQL 初階班
電子商務互動式網站實作中階
Dreamweaver多媒體網頁設計
Android手機程式開發班(2012年10月)
PHP & MySQL (2012年10月)
創意塗鴉
yahoo橫幅
google橫幅
市民學苑
第二屆樂活部落格
第一屆電腦設備簡易維護和故障排除班
專案訓練
電子商務創業班
TQC PHP認證
投資理財班
領隊導遊班
電腦基礎及網路應用身心障礙專班
應用軟體網頁化開發
[收藏此主題]
[關注此主題的新回復]
[通過 QQ、MSN 分享給朋友]