Created
December 1, 2017 06:40
-
-
Save ammardev/4d13c9e954959befbec7fbf0d5222645 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.HashSet; | |
/** | |
* Created on 11/30/17 | |
* | |
* @author <a href="mailto:[email protected]">Ammar Al-khawaldeh</a> | |
*/ | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
String line; | |
String grid[][] = new String[9][9]; | |
for (int i = 0; i < 9; i++) { | |
line = reader.readLine(); | |
if (line.charAt(0) != '|') { | |
i--; | |
continue; | |
} | |
line = line.substring(2, 23).replaceAll(" \\|", ""); | |
grid[i] = line.split(" "); | |
} | |
HashSet<Integer> row = new HashSet<>(); | |
HashSet<Integer> col = new HashSet<>(); | |
int rowItem; | |
int colItem; | |
for (int i = 0; i < 9; i++) { | |
for (int j = 0; j < 9; j++) { | |
rowItem = Integer.parseInt(grid[j][i]); | |
colItem = Integer.parseInt(grid[i][j]); | |
if (rowItem < 1 || rowItem > 9 || colItem < 1 || colItem > 9) { | |
System.out.println("Invalid"); | |
return; | |
} | |
row.add(rowItem); | |
col.add(colItem); | |
} | |
System.out.println("row: " + row); | |
System.out.println("col: " + col); | |
if (row.size() < 9 || col.size() < 9) { | |
System.out.println("Invalid"); | |
return; | |
} | |
row.clear(); | |
col.clear(); | |
} | |
System.out.println("valid"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment