#37770: 不懂為什麼會出錯


sheep60320@gmail.com (y yang)

學校 : 不指定學校
編號 : 249953
來源 : [60.251.178.3]
最後登入時間 :
2023-10-13 14:39:18
b965. 2. 矩陣轉換 -- 2016年3月apcs | From: [122.146.89.81] | 發表日期 : 2023-10-06 10:45

import java.util.Scanner;

 

//矩陣轉換
public class b965 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);

 

while(s.hasNext()){
int[] a = new int[3];
for(int i = 0; i < 3; i++){
a[i] = s.nextInt();
}
int[][] d = new int[a[0]][a[1]];
for(int i = 0; i < a[0]; i++){
for(int j = 0; j < a[1]; j++){
d[i][j] = s.nextInt();
}
}
int[] b = new int[a[2]];
for(int i = 0; i < a[2]; i++){
b[i] = s.nextInt();
}
int x = a[1];
int y = a[0];
for(int i = a[2]; i > 0; i--){
int temp;
if((b[i - 1] == 0) && (x > 1) && (y > 1)){
int[][] d2 = new int[x][y];
for(int j = 0; j < x; j++){
int[] row = new int[y];
for(int k = 0; k < y; k++){
row[k] = d[k][j];
}
d2[x-j-1] = row;
}
d = d2;
temp = x;
x = y;
y = temp;
}else if((b[i - 1] == 1) && (y > 1)){
for(int j = 0; j <= (y/2); j++){
for(int k = 0; k < x; k++){
temp = d[j][k];
d[j][k] = d[y-j-1][k];
d[y-j-1][k] = temp;
}
}
}
}

 

System.out.print(d.length + " " + d[0].length);
System.out.println();
for(int i = 0; i < d.length; i++){
for(int j = 0; j < d[0].length; j++){
System.out.print(d[i][j]);
if(j < d[0].length-1){
System.out.print(" ");
}
}
System.out.println();
}
 
}
s.close();
}
}
 
自己本地測試都是正確的,
我用java寫,錯誤訊息如下

#0: 30% WA (line:44)

您的答案為: 1 5 6 1 0
正確答案為: 2 9 3 1 2

#1: 70% WA (line:9)

您的答案為: 0 9 4 3 1 9 6 5 6
正確答案為: 5 0 7 0 8 1 5 0 3

如果沒加上while錯誤訊息變成

#0: 30% WA (line:7)

您只輸出了 6 行。

#1: 70% WA (line:5)

您只輸出了 4 行。
 
#37861: Re: 不懂為什麼會出錯


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
b965. 2. 矩陣轉換 -- 2016年3月apcs | From: [101.137.221.7] | 發表日期 : 2023-10-14 18:02

1.
if((b[i - 1] == 0) && (x > 1) && (y > 1)){
2.
for(int j = 0; j <= (y/2); j++){
 


1. x或y為1時會出錯

2. <=改成<

 
ZeroJudge Forum