Untitled

 avatar
unknown
plain_text
2 years ago
2.2 kB
5
Indexable
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
		String input = scanner.nextLine();
		String border = "---------";
		int counter = 0;
		char[][] symbolsArray = new char[3][3];
		for (int i = 0; i < 3; i++) {
		    for (int j = 0; j < 3; j++) {
		        symbolsArray[i][j] = input.charAt(counter);
		        counter++;
		    }
		}
		
		System.out.println(border);
		for (int i = 0; i < 3; i++) {
		    System.out.print("| ");
		    for (int j = 0; j < 3; j++) {
		        System.out.print(symbolsArray[i][j]);
                System.out.print(" ");
		    }
		    System.out.println("|");
		    if (counter < 7) {
		        System.out.println();
		    }
		    
		}
		System.out.println(border);
        
        boolean cont = true;
        int x = 0;
        int y = 0;
        
        for (int i = 0; i < input.length(); i++) {
            
            if (input.charAt(i) == 'x') {
                x++;
                continue;
        }
            if (input.charAt(i) == 'o') {
                y++;
            }
        
        }
        
        if (Math.abs(x - y) > 1) {
            System.out.println("Impossible");
            cont = false;
        } else if (x + y < 9) {
            System.out.println("Game not finished");
            cont = false;
        }
        
        if (continue) {
            
            int[][] combinations = {
            {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6},
            {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}
        };
        
        for (int i = 0; i < 3; i++) {
            x = 0;
            y = 0;
            for(int j = 0; j < 3; j++) {
                if (input.charAt(combinations[i][j]) == 'x') {
                    x++;
                    continue;
                }
                if (input.charAt(combinations[i][j]) == 'o') {
                    y++;
                }
                
            }
            
            if (x == 3) {
                System.out.println("X wins");
                break;
            }
        }
            
        } 
        
        
           
    }
}
Editor is loading...