Created
August 30, 2013 09:01
-
-
Save w00lf/6387865 to your computer and use it in GitHub Desktop.
********Судоку********
http://acmp.ru/index.asp?main=task&id_task=88
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.math.BigInteger; | |
import java.util.*; | |
public class Main{ | |
public static void main(String[] argv) throws IOException,Exception{ | |
new Main().run(); | |
} | |
public static StreamTokenizer sc ; | |
public static int nextInt() throws Exception{ | |
sc.nextToken(); | |
return (int)sc.nval; | |
} | |
public void run() throws IOException,Exception{ | |
sc = new StreamTokenizer(new BufferedReader(new FileReader("input.txt"))); | |
int n = nextInt(); | |
int n2 = (int)Math.pow(n,2); | |
Boolean[] rows_fill = new Boolean[n2]; | |
Boolean[][] column_fill = new Boolean[n2][n2]; | |
for (int i = 0; i < column_fill.length; i++) { | |
Arrays.fill(column_fill[i], false); | |
} | |
int[][] temp = new int[n][n2]; | |
for (int i = 0; i < n; i++) { | |
Arrays.fill(rows_fill, false); | |
for (int j = 0; j < n; j++) { | |
for (int k = 0; k < n2; k++) { | |
temp[j][k] = nextInt(); | |
if (temp[j][k] > n2 || temp[j][k] < 1) { | |
print_answer(false); | |
} | |
rows_fill[temp[j][k]-1] = true; | |
column_fill[temp[j][k]-1][k] = true; | |
} | |
answer_exit(rows_fill); | |
} | |
Arrays.fill(rows_fill, false); | |
for (int j = 0; j < n2; j+=n) { | |
for (int k = 0; k < n; k++) { | |
for (int l = j; l < n; l++) { | |
if (temp[k][l] == 0) { | |
continue; | |
} | |
rows_fill[temp[k][l]-1] = true; | |
} | |
} | |
answer_exit(rows_fill); | |
} | |
} | |
for (int i = 0; i < column_fill.length; i++) { | |
answer_exit(column_fill[i]); | |
} | |
print_answer(true); | |
} | |
public static void answer_exit(Boolean[] fillen) throws FileNotFoundException { | |
if (Arrays.asList(fillen).contains(false)) { | |
print_answer(false); | |
} | |
} | |
public static void print_answer(Boolean answer) throws FileNotFoundException { | |
PrintWriter pw = new PrintWriter(new File("output.txt")); | |
String result = answer ? "Correct" : "Incorrect"; | |
pw.write(result); | |
pw.close(); | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment