Kattis: 10 Kinds of People [on hold]
https://open.kattis.com/problems/10kindsofpeople
When i submit my code on Kattis judge i get RuntimeException in first run.
I'm 100% sure logic in my code solving this problem. My submission is resolving two test cases, I also created randomly generated input within range of this problem and my code never gave me RuntimeException
.
import java.util.Arrays;
import java.util.Scanner;
public class OneZeroKindsOfPeople {
private char map;
private char mark;
private int r1, c1, r2, c2;
private int cmax, rmax;
private int visited;
private Scanner scanner;
public void solve() {
scanner = new Scanner(System.in);
getMap();
scanner.reset();
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
mark = '0';
getPositions();
if (checkSamePosition()) {
if (map[r1][c1] == '0') System.out.println("binary");
else System.out.println("decimal");
} else {
createVisited();
if (checkRoute()) {
System.out.println("binary");
} else {
createVisited();
mark = '1';
if (checkRoute()) System.out.println("decimal");
else System.out.println("neither");
}
}
}
scanner.close();
}
private boolean checkSamePosition() {
return r1 == r2 && c1 == c2;
}
private void createVisited() {
visited = new int[rmax][cmax];
for (int i = 0; i < rmax; i++) {
Arrays.fill(visited[i], 0);
}
}
private boolean checkRoute() {
return checkRouteREC(r1, c1);
}
private boolean checkRouteREC(int r, int c) {
if (r < 0 || r >= rmax || c < 0 || c >= cmax) return false;
if (r == r2 && c == c2 && map[r][c] == mark) return true;
if (visited[r][c] == 1) return false;
if (map[r][c] != mark) return false;
visited[r][c] = 1;
return checkRouteREC(r + 1, c) || checkRouteREC(r - 1, c) || checkRouteREC(r, c + 1) || checkRouteREC(r, c - 1);
}
private void getPositions() {
scanner.reset();
scanner = new Scanner(System.in);
r1 = scanner.nextInt() - 1;
c1 = scanner.nextInt() - 1;
r2 = scanner.nextInt() - 1;
c2 = scanner.nextInt() - 1;
}
private void getMap() {
rmax = scanner.nextInt();
cmax = scanner.nextInt();
map = new char[rmax][cmax];
for (int i = 0; i < rmax; i++) {
map[i] = scanner.next().toCharArray();
}
}
public static void main(String args) {
OneZeroKindsOfPeople problem = new OneZeroKindsOfPeople();
problem.solve();
}
}
Analyzing my poorly written code is probably too much to ask, but maybe you can give me a clue what can I fix?
java programming-challenge
New contributor
put on hold as off-topic by Hosch250, πάντα ῥεῖ, Vogel612♦ Dec 27 '18 at 18:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, πάντα ῥεῖ, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
https://open.kattis.com/problems/10kindsofpeople
When i submit my code on Kattis judge i get RuntimeException in first run.
I'm 100% sure logic in my code solving this problem. My submission is resolving two test cases, I also created randomly generated input within range of this problem and my code never gave me RuntimeException
.
import java.util.Arrays;
import java.util.Scanner;
public class OneZeroKindsOfPeople {
private char map;
private char mark;
private int r1, c1, r2, c2;
private int cmax, rmax;
private int visited;
private Scanner scanner;
public void solve() {
scanner = new Scanner(System.in);
getMap();
scanner.reset();
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
mark = '0';
getPositions();
if (checkSamePosition()) {
if (map[r1][c1] == '0') System.out.println("binary");
else System.out.println("decimal");
} else {
createVisited();
if (checkRoute()) {
System.out.println("binary");
} else {
createVisited();
mark = '1';
if (checkRoute()) System.out.println("decimal");
else System.out.println("neither");
}
}
}
scanner.close();
}
private boolean checkSamePosition() {
return r1 == r2 && c1 == c2;
}
private void createVisited() {
visited = new int[rmax][cmax];
for (int i = 0; i < rmax; i++) {
Arrays.fill(visited[i], 0);
}
}
private boolean checkRoute() {
return checkRouteREC(r1, c1);
}
private boolean checkRouteREC(int r, int c) {
if (r < 0 || r >= rmax || c < 0 || c >= cmax) return false;
if (r == r2 && c == c2 && map[r][c] == mark) return true;
if (visited[r][c] == 1) return false;
if (map[r][c] != mark) return false;
visited[r][c] = 1;
return checkRouteREC(r + 1, c) || checkRouteREC(r - 1, c) || checkRouteREC(r, c + 1) || checkRouteREC(r, c - 1);
}
private void getPositions() {
scanner.reset();
scanner = new Scanner(System.in);
r1 = scanner.nextInt() - 1;
c1 = scanner.nextInt() - 1;
r2 = scanner.nextInt() - 1;
c2 = scanner.nextInt() - 1;
}
private void getMap() {
rmax = scanner.nextInt();
cmax = scanner.nextInt();
map = new char[rmax][cmax];
for (int i = 0; i < rmax; i++) {
map[i] = scanner.next().toCharArray();
}
}
public static void main(String args) {
OneZeroKindsOfPeople problem = new OneZeroKindsOfPeople();
problem.solve();
}
}
Analyzing my poorly written code is probably too much to ask, but maybe you can give me a clue what can I fix?
java programming-challenge
New contributor
put on hold as off-topic by Hosch250, πάντα ῥεῖ, Vogel612♦ Dec 27 '18 at 18:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, πάντα ῥεῖ, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
2
Welcome to Code Review! We review working code here; we don't offer help debugging code, as explained in our help center. We'd be happy to help you improve your code after you fix the bug!
– Graham
Dec 27 '18 at 18:14
Are there any details beside the name of exception? Try submitting only input reading part of code, so you are suregetPositions
andgetMap
is ok.
– user158037
Dec 28 '18 at 14:23
add a comment |
https://open.kattis.com/problems/10kindsofpeople
When i submit my code on Kattis judge i get RuntimeException in first run.
I'm 100% sure logic in my code solving this problem. My submission is resolving two test cases, I also created randomly generated input within range of this problem and my code never gave me RuntimeException
.
import java.util.Arrays;
import java.util.Scanner;
public class OneZeroKindsOfPeople {
private char map;
private char mark;
private int r1, c1, r2, c2;
private int cmax, rmax;
private int visited;
private Scanner scanner;
public void solve() {
scanner = new Scanner(System.in);
getMap();
scanner.reset();
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
mark = '0';
getPositions();
if (checkSamePosition()) {
if (map[r1][c1] == '0') System.out.println("binary");
else System.out.println("decimal");
} else {
createVisited();
if (checkRoute()) {
System.out.println("binary");
} else {
createVisited();
mark = '1';
if (checkRoute()) System.out.println("decimal");
else System.out.println("neither");
}
}
}
scanner.close();
}
private boolean checkSamePosition() {
return r1 == r2 && c1 == c2;
}
private void createVisited() {
visited = new int[rmax][cmax];
for (int i = 0; i < rmax; i++) {
Arrays.fill(visited[i], 0);
}
}
private boolean checkRoute() {
return checkRouteREC(r1, c1);
}
private boolean checkRouteREC(int r, int c) {
if (r < 0 || r >= rmax || c < 0 || c >= cmax) return false;
if (r == r2 && c == c2 && map[r][c] == mark) return true;
if (visited[r][c] == 1) return false;
if (map[r][c] != mark) return false;
visited[r][c] = 1;
return checkRouteREC(r + 1, c) || checkRouteREC(r - 1, c) || checkRouteREC(r, c + 1) || checkRouteREC(r, c - 1);
}
private void getPositions() {
scanner.reset();
scanner = new Scanner(System.in);
r1 = scanner.nextInt() - 1;
c1 = scanner.nextInt() - 1;
r2 = scanner.nextInt() - 1;
c2 = scanner.nextInt() - 1;
}
private void getMap() {
rmax = scanner.nextInt();
cmax = scanner.nextInt();
map = new char[rmax][cmax];
for (int i = 0; i < rmax; i++) {
map[i] = scanner.next().toCharArray();
}
}
public static void main(String args) {
OneZeroKindsOfPeople problem = new OneZeroKindsOfPeople();
problem.solve();
}
}
Analyzing my poorly written code is probably too much to ask, but maybe you can give me a clue what can I fix?
java programming-challenge
New contributor
https://open.kattis.com/problems/10kindsofpeople
When i submit my code on Kattis judge i get RuntimeException in first run.
I'm 100% sure logic in my code solving this problem. My submission is resolving two test cases, I also created randomly generated input within range of this problem and my code never gave me RuntimeException
.
import java.util.Arrays;
import java.util.Scanner;
public class OneZeroKindsOfPeople {
private char map;
private char mark;
private int r1, c1, r2, c2;
private int cmax, rmax;
private int visited;
private Scanner scanner;
public void solve() {
scanner = new Scanner(System.in);
getMap();
scanner.reset();
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
mark = '0';
getPositions();
if (checkSamePosition()) {
if (map[r1][c1] == '0') System.out.println("binary");
else System.out.println("decimal");
} else {
createVisited();
if (checkRoute()) {
System.out.println("binary");
} else {
createVisited();
mark = '1';
if (checkRoute()) System.out.println("decimal");
else System.out.println("neither");
}
}
}
scanner.close();
}
private boolean checkSamePosition() {
return r1 == r2 && c1 == c2;
}
private void createVisited() {
visited = new int[rmax][cmax];
for (int i = 0; i < rmax; i++) {
Arrays.fill(visited[i], 0);
}
}
private boolean checkRoute() {
return checkRouteREC(r1, c1);
}
private boolean checkRouteREC(int r, int c) {
if (r < 0 || r >= rmax || c < 0 || c >= cmax) return false;
if (r == r2 && c == c2 && map[r][c] == mark) return true;
if (visited[r][c] == 1) return false;
if (map[r][c] != mark) return false;
visited[r][c] = 1;
return checkRouteREC(r + 1, c) || checkRouteREC(r - 1, c) || checkRouteREC(r, c + 1) || checkRouteREC(r, c - 1);
}
private void getPositions() {
scanner.reset();
scanner = new Scanner(System.in);
r1 = scanner.nextInt() - 1;
c1 = scanner.nextInt() - 1;
r2 = scanner.nextInt() - 1;
c2 = scanner.nextInt() - 1;
}
private void getMap() {
rmax = scanner.nextInt();
cmax = scanner.nextInt();
map = new char[rmax][cmax];
for (int i = 0; i < rmax; i++) {
map[i] = scanner.next().toCharArray();
}
}
public static void main(String args) {
OneZeroKindsOfPeople problem = new OneZeroKindsOfPeople();
problem.solve();
}
}
Analyzing my poorly written code is probably too much to ask, but maybe you can give me a clue what can I fix?
java programming-challenge
java programming-challenge
New contributor
New contributor
edited Dec 27 '18 at 18:09
alecxe
14.9k53478
14.9k53478
New contributor
asked Dec 27 '18 at 17:08
H. Zablocki
11
11
New contributor
New contributor
put on hold as off-topic by Hosch250, πάντα ῥεῖ, Vogel612♦ Dec 27 '18 at 18:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, πάντα ῥεῖ, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Hosch250, πάντα ῥεῖ, Vogel612♦ Dec 27 '18 at 18:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, πάντα ῥεῖ, Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
2
Welcome to Code Review! We review working code here; we don't offer help debugging code, as explained in our help center. We'd be happy to help you improve your code after you fix the bug!
– Graham
Dec 27 '18 at 18:14
Are there any details beside the name of exception? Try submitting only input reading part of code, so you are suregetPositions
andgetMap
is ok.
– user158037
Dec 28 '18 at 14:23
add a comment |
2
Welcome to Code Review! We review working code here; we don't offer help debugging code, as explained in our help center. We'd be happy to help you improve your code after you fix the bug!
– Graham
Dec 27 '18 at 18:14
Are there any details beside the name of exception? Try submitting only input reading part of code, so you are suregetPositions
andgetMap
is ok.
– user158037
Dec 28 '18 at 14:23
2
2
Welcome to Code Review! We review working code here; we don't offer help debugging code, as explained in our help center. We'd be happy to help you improve your code after you fix the bug!
– Graham
Dec 27 '18 at 18:14
Welcome to Code Review! We review working code here; we don't offer help debugging code, as explained in our help center. We'd be happy to help you improve your code after you fix the bug!
– Graham
Dec 27 '18 at 18:14
Are there any details beside the name of exception? Try submitting only input reading part of code, so you are sure
getPositions
and getMap
is ok.– user158037
Dec 28 '18 at 14:23
Are there any details beside the name of exception? Try submitting only input reading part of code, so you are sure
getPositions
and getMap
is ok.– user158037
Dec 28 '18 at 14:23
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
Welcome to Code Review! We review working code here; we don't offer help debugging code, as explained in our help center. We'd be happy to help you improve your code after you fix the bug!
– Graham
Dec 27 '18 at 18:14
Are there any details beside the name of exception? Try submitting only input reading part of code, so you are sure
getPositions
andgetMap
is ok.– user158037
Dec 28 '18 at 14:23