#10653: Java 寫法分享


smart70094 (Scorpius)


import java.util.*;
class JAVA {
public static void main(String args[]) {
Scanner inp=new Scanner(System.in);
int table[][]=new int[9][9];

while(inp.hasNext()) {
boolean yn=true;
//↓讀檔
for (int i=0;i<=8;i++) {
for (int j=0;j<=8;j++) {
table[i][j]=inp.nextInt();
}
}
//↓行列判斷加起來是否等於90
int check_total=0;
int dot[]={0,3,6,27,30,33,54,57,60};
for (int i=0;i<=8;i++) {
check_total=0;
for (int j=0;j<=8;j++) {
check_total+=table[i][j];
check_total+=table[j][i];
}
if(check_total!=90) {
yn=false;
break;
}
}
//↓九宮格判斷,共有九個九個宮格,用多維轉一維記錄每個九宮格左上角的座標,在用迴圈計算加起來是否等於45;
if(yn==true) {
for (int n=0;n<=8;n++) {
int t=dot[n];

check_total=0;
for (int i=0;i<=2;i++){
for (int j=0;j<=2;j++) {
int px=t / 9;
int py=t %9;
check_total+=table[px][py];
t++;
}
t=t-3+9;
}
if(check_total!=45) {
yn=false;
break;
}
}
}
if (yn==true) {
System.out.println("yes");
}else {
System.out.println("no");
}
}
}
}