输入一串数字,代表下棋步骤,甲为先手乙为后手,输出"jia win"或者"yi win"或者平局“drew”
棋盘为
1 2 3
4 5 6
7 8 9
- import java.util.Scanner;
-
- /**
- * 给一串数字,代表下棋的步骤
- * 甲为先手,乙为后手
- * 判断输赢
- * 棋盘为
- * 1,2,3
- * 4,5,6
- * 7,8,9
- */
- public class JingZiQi {
-
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String str = sc.nextLine();
- int[][] chuan = new int[][]{
- {1,2,3},
- {4,5,6},
- {7,8,9}
- };
- for(int i=0;i
- for(int j=0;j<3;j++){
- for(int k=0;k<3;k++){
- if(chuan[j][k] == Integer.parseInt(str.substring(i,i+1))){
- if(i%2==0){
- chuan[j][k] = 0;
- }else {
- chuan[j][k] = -1;
- }
- }
- }
- }
- }
- for(int j = 0; j < 3; j++) {
- for (int k = 0; k < 3; k++) {
- System.out.print(chuan[j][k]+" ");
- }
- System.out.println();
- }
-
- for(int i=0;i<3;i++){
- if(chuan[0][i]==0&&chuan[1][i]==0&&chuan[2][i]==0){
- System.out.println("jia win");
- return;
- }
- if(chuan[0][i]==-1&&chuan[1][i]==-1&&chuan[2][i]==-1){
- System.out.println("yi win");
- return;
- }
- if(chuan[i][0]==0&&chuan[i][1]==0&&chuan[i][2]==0){
- System.out.println("jia win");
- return;
- }
- if(chuan[i][0]==-1&&chuan[i][1]==-1&&chuan[i][2]==-1){
- System.out.println("yi win");
- return;
- }
- }
- if(chuan[0][0]==0&&chuan[1][1]==0&&chuan[2][2]==0){
- System.out.println("jia win");
- return;
- }
- if(chuan[0][0]==-1&&chuan[1][1]==-1&&chuan[2][2]==-1){
- System.out.println("yi win");
- return;
- }
- System.out.println("drew");
- return;
- }
-
-
- }
-
-
示例:
输入:5234689
输出:jia win