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 scn = new Scanner(System.in); | |
int n=scn.nextInt(); | |
int arr[][]=new int[3][3]; | |
for(int i=0;i<3;i++) | |
for(int j=0;j<3;j++) | |
arr[i][j]=scn.nextInt(); | |
String s=""; | |
for(int i=0;i<3;i++){ | |
if(arr[i][0]==arr[i][1]&&arr[i][1]==arr[i][2]&&arr[i][0]==n){ | |
s+="All "+n+"'s on row "+i+"\n"; | |
} | |
} | |
for(int i=0;i<3;i++){ | |
if(arr[0][i]==arr[1][i]&&arr[1][i]==arr[2][i]&&arr[0][i]==n){ | |
s+="All "+n+"'s on column "+i+"\n"; | |
} | |
} | |
if(arr[0][0]==arr[1][1]&&arr[1][1]==arr[2][2]&&arr[0][0]==n) | |
s+="All "+n+"'s on diagonal\n"; | |
if(arr[0][2]==arr[1][1]&&arr[1][1]==arr[2][0]&&arr[0][2]==n) | |
s+="All "+n+"'s on subdiagonal\n"; | |
if(s.length()>0) | |
System.out.print(s); | |
else | |
System.out.println("There is no line with all "+n); | |
} | |
/*題目:[C_AR151-易] 井字遊戲判斷 | |
作者:1010 | |
時間:西元 2017 年 4 月 */ | |
} |
這題就是把八種連線可能方式一一去檢查,若完全無則輸出There is no line with all ?
(?為該數)
沒有留言:
張貼留言