import java.util.*;
import java.math.*;
//rename the class name before submitting
public class FoxAndGomoku {
public static void main(String[] args) {
FoxAndGomoku obj = new FoxAndGomoku();
System.out.println(
obj.win(
null
));
}
public String win(String[] board) {
int n = board.length;
for (int y = 0; y < n; y++) {
for (int x = 0; x < n; x++) {
// check hor
if (x + 5 <= n) {
int no = 0;
for (int i = x; i < x + 5; i++) {
if (board[y].charAt(i) == 'o')
no++;
}
if (no == 5)
return "found";
}
// check ver
if (y + 5 <= n) {
int no = 0;
for (int i = y; i < y + 5; i++) {
if (board[i].charAt(x) == 'o')
no++;
}
if (no == 5)
return "found";
}
// check right
if (x + 5 <= n && y + 5 <= n) {
int no = 0;
for (int i = 0; i < 5; i++) {
if (board[x + i].charAt(y + i) == 'o')
no++;
}
if (no == 5)
return "found";
}
// check left
if (x + 5 <= n && y + 5 <= n) {
int no = 0;
for (int i = 0; i < 5; i++) {
if (board[x + i].charAt(y + 4 - i) == 'o')
no++;
}
if (no == 5)
return "found";
}
}
}
return "not found";
}
}
No comments:
Post a Comment