作者kevin771012 ()
看板java
標題[問題] 矩陣翻轉的問題
時間Sat Mar 5 09:55:18 2011
ACM的練習題
輸入說明 :
第一行會有兩個數字,分別為 列(row)<100 和 行(column)<100,緊接著就是這個矩陣的
內容
輸出說明 :
直接輸出翻轉後的矩陣
我的答案 :
//a015: 矩陣的翻轉
import java.util.Scanner;
public class a015 {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int a,b;
a = sin.nextInt();
b = sin.nextInt();
int number[][] = new int[a][b];
for(int row =0;row<a;row++){
for(int commun=0;commun<b;commun++){
number[row][commun] = sin.nextInt();
}
}
for(int commun=0;commun<b;commun++){
for(int row=0;row<a;row++){
System.out.print(number[row][commun]+ " ");
}
System.out.println();
}
}
}
想法是直接將他的行跟列數字顛倒就好,不過跑到RE
不知道為什麼會這樣@@
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.83.163.233
→ chchwy:矩陣不一定是方陣唷 你想想3x5矩陣轉過來是5x3 03/05 11:34
→ chchwy:對不起 我犯傻了 請無視我orz 03/05 11:42
→ tkcn:一個比較無關的事,你的 column 拼錯了 03/05 12:22
→ kevin771012:英文不好~XD 看了一下它錯誤的內容是說索引超過 03/05 19:10