#28329: 請問發生了甚麼問題?(UVA能過這裡不能)


will901024 (The joke is on me)

學校 : 臺中市私立致用高級中學
編號 : 158385
來源 : [211.20.7.115]
最後登入時間 :
2023-11-23 22:52:52
e513. 11349 - Symmetric Matrix -- UVA | From: [125.230.50.243] | 發表日期 : 2021-11-29 21:06

#0: 50% WA (line:8)

您的答案為: Test #8: Symmetric.
正確答案為: Test #8: Non-symmetric.

#1: 50% WA (line:1)

您的答案為: Test #1: Symmetric.
正確答案為: Test #1: Non-symmetric.


import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int a=1;a<=t;a++) {
String ch=sc.next(),mark=sc.next();
int n = sc.nextInt();
long array[] = new long[n*n];
for (int i = 0; i < n*n; i++) {
array[i] = sc.nextLong();
}
boolean ans=true;
for (int i = array.length-1, j = 0; i > j; i--, j++) {
if ((array[i] != array[j])||array[i]<0||array[j]<0) {
ans=false;
break;
}
}
if(ans==true){
System.out.println("Test #"+a+": Symmetric.");
}
else{
System.out.println("Test #"+a+": Non-symmetric.");
}
}
}
}
 
#28330: Re:請問發生了甚麼問題?(UVA能過這裡不能)


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
e513. 11349 - Symmetric Matrix -- UVA | From: [39.12.131.96] | 發表日期 : 2021-11-30 08:51

            for (int i = array.length-1, j = 0; i > j; i--, j++) {


當i==j(也就是正中間)時有可能小於0,你沒有判斷到這個狀況

 
#28331: Re:請問發生了甚麼問題?(UVA能過這裡不能)


will901024 (The joke is on me)

學校 : 臺中市私立致用高級中學
編號 : 158385
來源 : [211.20.7.115]
最後登入時間 :
2023-11-23 22:52:52
e513. 11349 - Symmetric Matrix -- UVA | From: [125.230.50.243] | 發表日期 : 2021-11-30 09:52

            for (int i = array.length-1, j = 0; i > j; i--, j++) {


當i==j(也就是正中間)時有可能小於0,你沒有判斷到這個狀況


謝謝

 
ZeroJudge Forum