For some reason the code does not increment the 2 arrays i.e xa[] and yarray[] when the conditions are met. This is supposed to be the solution to the code jam 2019 round 1B question manhaton the question can be found
here. If you could help me I would he highly grateful.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int cases = input.nextInt();
for (int a = 1; a <= cases; a++) {
int people = input.nextInt();
int length = input.nextInt();
int[] xa = new int[length];
int[] yarray = new int[length];
for (int b = 1; b <= people; b++) {
int xd = input.nextInt();
int yd = input.nextInt();
String direction = input.next();
if (direction =="N") {
for (int c = (yd + 1); c < length; c++) {
yarray[c]+=1;
}
}
else if (direction == "S") {
for (int v = (yd - 1); v >= 0; v--) {
yarray[v]+=1;
}
}
else if (direction == "E") {
for (int o = (xd + 1); o < length; o++) {
xa[o]+=1;
}
}
else if (direction == "W") {
for (int m = (xd - 1); m >= 0; m--) {
xa[m]+=1;
}
}
}
int max = xa[0];
int xcord = 0;
for(int i = 0; i < length; i++)
{
if(max < xa[i])
{
max = xa[i];
xcord=i;
}
}
int maxy = yarray[0];
int ycor=0;
for(int i = 0; i < length; i++)
{
if(maxy < yarray[i]) {
maxy = yarray[i];
ycor=i;
}
}
System.out.println("Case #" + a + ": " + xcord + " "+ ycor);
}
}
}
Sample Input :
3
1 10
5 5 N
4 10
2 4 N
2 6 S
1 5 E
3 5 W
8 10
0 2 S
0 3 N
0 3 N
0 4 N
0 5 S
0 5 S
0 8 S
1 5 W
What I have tried:
I have tried changing the increment statements and I have tried changing the loop statements but had no success.