Advertisement
roronoa

sudoku

May 1st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. class Solution {
  5.     public static void main(String args[])
  6.     {
  7.         Scanner in = new Scanner(System.in);
  8.         char mat[][] = new char[9][9];
  9.         char res[][] = new char[9][9];
  10.         int subSquare=0; //max=8;
  11.         for (int i = 0; i < 9; i++) {
  12.             for (int j = 0; j < 9; j++) {
  13.                 String x = in.nextLine();
  14.                 mat[i]=x.toCharArray();
  15.             }
  16.         }
  17.         int l = 0, c = 0;
  18.         int x = 0;
  19.         for(int i = 0; i < 9; i++)
  20.         {
  21.             for(int j = 0; j < 9; j++)
  22.             {
  23.                 //col = 3*i
  24.                 res[i][j]=mat[l][c];
  25.                 c++;
  26.                 if(c%3==0)
  27.                 {
  28.                     c = x;
  29.                     l++;
  30.                 }
  31.                 if(l%3 == 0)
  32.                 {
  33.                     l = 0;
  34.                     c+=3;
  35.                 }
  36.                
  37.             }
  38.         }
  39.         for(int i = 0; i < 9; i++)
  40.         {
  41.             for(int j = 0; j < 9; j++)
  42.             {
  43.                 System.out.print(res[i][j]);
  44.                 if(j==8)
  45.                     System.out.println();
  46.                 else
  47.                     System.out.print(" ");
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement