Yahya-Ak-Ayoub

antiSudoku

Mar 19th, 2021 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class antiSudoku {
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.  
  9.         BufferedReader reader
  10.                 = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12.         int tc = Integer.parseInt(reader.readLine());
  13.         int y[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}, x[] = {0, 3, 6, 1, 4, 7, 2, 5, 8};
  14.         char mat[][] = new char[9][9];
  15.         for (int i = 0; i < tc; i++) {//sudoku
  16.             for (int j = 0; j < 9; j++) {// Lines
  17.                 char arr[] = reader.readLine().toCharArray();
  18.                 for (int q = 0; q < 9; q++) {
  19.                     mat[j][q] = arr[q];
  20.                 }
  21.             }
  22.  
  23.             for (int e = 0; e < 9; e++) {
  24.                 int number = Integer.parseInt(mat[y[e]][x[e]] + "");
  25.                 if (number < 9) {
  26.                     mat[y[e]][x[e]] = ((number + 1) + "").charAt(0);
  27.                 } else {
  28.                     mat[y[e]][x[e]] = ((number - 1) + "").charAt(0);
  29.                 }
  30.             }
  31.  
  32.             for (int e = 0; e < 9; e++) {
  33.                 System.out.println(mat[e]);
  34.             }
  35.         }
  36.     }
  37.  
  38. }
Add Comment
Please, Sign In to add comment