題目連結
題意:
測資只有一組
給定好幾行字串
整段文字順時針90度後輸出
解法:
用二維陣列存
index 設計一下輸出即可
字串長短不一時,要記得補空格
程式(Java):
題意:
測資只有一組
給定好幾行字串
整段文字順時針90度後輸出
解法:
用二維陣列存
index 設計一下輸出即可
字串長短不一時,要記得補空格
程式(Java):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String args[]) { | |
Scanner sc = new Scanner(System.in); | |
char[][] data = new char[101][101]; | |
int lines = 0, max = 0; | |
while (sc.hasNext()){ | |
String s1 = sc.nextLine(); | |
max = (s1.length() > max) ? s1.length() : max; | |
for (int i = 0; i < s1.length(); i++) | |
data[lines][i] = s1.charAt(i); | |
lines++; | |
} | |
for (int j = 0; j < max; j++) { | |
for (int k = lines - 1; k >= 0; k--) { | |
if (data[k][j] == '\0') { | |
System.out.print(" "); | |
} else | |
System.out.print(data[k][j]); | |
} | |
System.out.println(); | |
} | |
} | |
} |
請問為什麼要設if (k != 0)
回覆刪除抱歉現在才看到..
刪除時間太久我也忘記怎麼想的QQ
那或許只是多餘的檢查機制
經過確認後,那行判斷式不影響結果
索性把它拿掉了
也謝謝您的發問!