CSES - Putka Open 2015 – 2/6 - Results
Submission details
Task:Sudoku
Sender:
Submission time:2015-08-16 21:02:11 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.19 sdetails
#2ACCEPTED0.20 sdetails
#3ACCEPTED0.19 sdetails
#4ACCEPTED0.20 sdetails
#5ACCEPTED0.19 sdetails

Code

import java.util.Scanner;


public class Main {
	
	public static void ratkaise(int[][] sudoku) {
		int y = 1;
		int x = 0;
		while(y < 9) {
				
				while(true) {
					boolean kay = true;
				
					sudoku[y][x]++;
					if(sudoku[y][x] == 10) {
						sudoku[y][x] = 0;
						if(x == 0) {
							y--;
							x = 8;
						} else {
							x--;
						}
						continue;
					}
					
					for (int i = 0; i < 9; i++) {
						if(sudoku[y][i] == sudoku[y][x] && i != x) {
							kay = false;
							break;
						}
					}
					for (int i = 0; i < 9; i++) {
						if(!kay)break;
						if(sudoku[i][x] == sudoku[y][x] && i != y) {
							kay = false;
							break;
						}
					}
					for (int i = 0; i < 9; i++) {
						if(!kay)break;
						int x1 = i%3 + 3 * (x/3);
						int y1 = i/3 + 3 * (y/3);
						
						if(sudoku[y1][x1] == sudoku[y][x] && (y1 != y || x1 != x)) {
							kay = false;
						}
						
					}
					if(kay)break;
				}
				
				x++;
				if(x == 9) {
					x = 0;
					y++;
				}
			}
		
	}
	

	public static void main(String[] args) {
		Scanner lukija = new Scanner(System.in);
		String rivi = lukija.nextLine();
		int[][] sudoku = new int[9][9];
		for (int i = 0; i < 9; i++) {
			sudoku[0][i] = Integer.parseInt(String.valueOf(rivi.charAt(i)));
		}
		ratkaise(sudoku);
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				System.out.print(sudoku[i][j]);
			}
			System.out.println();
		}
		lukija.close();
	}

}

Test details

Test 1

Verdict: ACCEPTED

input
592836471

correct output
592836471
836471592
471592836
928364715
364715928
...

user output
592836471
134257689
678149235
213465798
456798123
...

Test 2

Verdict: ACCEPTED

input
672935418

correct output
672935418
935418672
418672935
729354186
354186729
...

user output
672935418
134268579
589147236
213456897
456789123
...

Test 3

Verdict: ACCEPTED

input
329174658

correct output
329174658
174658329
658329174
291746583
746583291
...

user output
329174658
145268379
678359124
213485796
456791283
...

Test 4

Verdict: ACCEPTED

input
376958421

correct output
376958421
958421376
421376958
769584213
584213769
...

user output
376958421
124367589
589124367
213475698
457689132
...

Test 5

Verdict: ACCEPTED

input
875694321

correct output
875694321
694321875
321875694
756943218
943218756
...

user output
875694321
123578469
469123578
214356897
356789142
...