import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
StringTokenizer st=new StringTokenizer(line,";");
int n=Integer.parseInt(st.nextToken());
int arr[][]=new int[n][n];
StringTokenizer valz=new StringTokenizer(st.nextToken(),",");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j]=Integer.parseInt(valz.nextToken());
}
}
if(checkSoduku(arr)){
sb.append("True\n");
}else{
sb.append("False\n");
}
}
System.out.print(sb);
}
static boolean checkSoduku(int[][]arr){
int n=arr.length;
for(int i=0;i<n;i++){
boolean[] valz=new boolean[n+1];
for(int j=0;j<n;j++){
if(arr[i][j]>n){
return false;
}
valz[arr[i][j]]=true;
}
for(int j=1;j<valz.length;j++){
if(!valz[j]){
return false;
}
}
}
for(int i=0;i<n;i++){
boolean[] valz=new boolean[n+1];
for(int j=0;j<n;j++){
if(arr[j][i]>n){
return false;
}
valz[arr[j][i]]=true;
}
for(int j=1;j<valz.length;j++){
if(!valz[j]){
return false;
}
}
}
int sqX=(int) Math.sqrt(n);
for(int i=0;i<sqX*sqX;i+=sqX){
for(int j=0;j<sqX*sqX;j+=sqX){
boolean[] valz=new boolean[n+1];
for(int z=i;z<i+sqX;z++){
for(int k=j;k<j+sqX;k++){
valz[arr[z][k]]=true;
}
}
for(int z=1;z<valz.length;z++){
if(!valz[z]){
return false;
}
}
}
}
return true;
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
StringTokenizer st=new StringTokenizer(line,";");
int n=Integer.parseInt(st.nextToken());
int arr[][]=new int[n][n];
StringTokenizer valz=new StringTokenizer(st.nextToken(),",");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j]=Integer.parseInt(valz.nextToken());
}
}
if(checkSoduku(arr)){
sb.append("True\n");
}else{
sb.append("False\n");
}
}
System.out.print(sb);
}
static boolean checkSoduku(int[][]arr){
int n=arr.length;
for(int i=0;i<n;i++){
boolean[] valz=new boolean[n+1];
for(int j=0;j<n;j++){
if(arr[i][j]>n){
return false;
}
valz[arr[i][j]]=true;
}
for(int j=1;j<valz.length;j++){
if(!valz[j]){
return false;
}
}
}
for(int i=0;i<n;i++){
boolean[] valz=new boolean[n+1];
for(int j=0;j<n;j++){
if(arr[j][i]>n){
return false;
}
valz[arr[j][i]]=true;
}
for(int j=1;j<valz.length;j++){
if(!valz[j]){
return false;
}
}
}
int sqX=(int) Math.sqrt(n);
for(int i=0;i<sqX*sqX;i+=sqX){
for(int j=0;j<sqX*sqX;j+=sqX){
boolean[] valz=new boolean[n+1];
for(int z=i;z<i+sqX;z++){
for(int k=j;k<j+sqX;k++){
valz[arr[z][k]]=true;
}
}
for(int z=1;z<valz.length;z++){
if(!valz[z]){
return false;
}
}
}
}
return true;
}
}
No comments:
Post a Comment