+ 1

i m making a sudoku program and need to store values what should i choose multi dimensional array or a linkedlist of req numbers

1st Aug 2017, 2:05 AM
shobhit
shobhit - avatar
4 Réponses
+ 3
public class main { public static void main(String[] args) { // TODO Auto-generated method stub int a=0; int[][]m ={{8,2,7,1,5,3,9,6,4},{9,5,4,6,8,2,3,7,1},{1,3,6,4,7,9,5,8,2},{6,9,2,8,1,5,4,3,7},{5,7,3,9,4,4,2,1,8},{4,1,8,3,2,7,6,9,5},{7,6,5,2,9,8,1,4,3},{3,8,1,5,4,6,7,2,1},{2,4,9,7,3,1,8,5,6}} ; for (int d = 0; d < 3; d++) { for (int s= 0; s < 3; s++) { int[] temp = new int [9] ; for (int i =(3*d); i < (d+1)* 3; i++) { for (int j = (3*s); j < (s+1)*3; j++) { temp[m[i][j]-1]= -1 ; } } for (int k = 0; k < temp.length;k++) { if (temp[k]==0) { System.out.println("duplicated Element in the" + (s+1) + "_nt squre"); a++; } } } } for (int i = 0; i < 9; i++) { int[] temp = new int [9] ; for (int j = 0; j < 9; j++) { temp[m[i][j]-1] = -1 ; } for (int k = 0; k < temp.length;k++) { if (temp[k]==0) { System.out.println("row " + (i+1) + " has an error); a++; } } } for (int i = 0; i < 9; i++) { int[] temp = new int [9] ; for (int j = 0; j < 9; j++) { temp[m[0][j]-1] = -1 ; } for (int k = 0; k < temp.length;k++) { if (temp[k]==0) { System.out.print("column " + (i+1) + " has an error"); a++; } } } if(a==0) { system.out.printIn("correct sudoku puzzle") ; } else system.out.printIn("incorrect sudoku puzzle") ; } }
5th Aug 2017, 1:54 PM
Ali kh
Ali kh - avatar
0
but what should i use to store them
1st Aug 2017, 8:55 AM
shobhit
shobhit - avatar
0
woe!
5th Aug 2017, 3:23 PM
shobhit
shobhit - avatar
- 1
start from the cell. then a row or column, then a block. then let these building blocks make the whole grid. let each of them be a class of your design.
1st Aug 2017, 4:11 AM
Venkatesh Pitta
Venkatesh Pitta - avatar