import
java.util.*;
class
Pair<X, Y> {
public
final
X first;
public
final
Y second;
public
Pair(X first, Y second) {
this
.first = first;
this
.second = second;
}
}
public
class
Main {
public
static
List<Pair<Integer, Integer>> findPossibleMoves(
int
n,
int
x,
int
y) {
int
[] dx = {
2
,
2
,
1
,
1
, -
1
, -
1
, -
2
, -
2
};
int
[] dy = {
1
, -
1
,
2
, -
2
,
2
, -
2
,
1
, -
1
};
List<Pair<Integer, Integer>> moves =
new
ArrayList<>();
for
(
int
i =
0
; i <
8
; i++) {
int
newX = x + dx[i];
int
newY = y + dy[i];
if
(newX >=
0
&& newY >=
0
&& newX < n && newY < n) {
moves.add(
new
Pair<>(newX, newY));
}
}
Collections.sort(moves,
new
Comparator<Pair<Integer, Integer>>() {
@Override
public
int
compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
if
(p1.first.equals(p2.first)) {
return
p1.second.compareTo(p2.second);
}
return
p1.first.compareTo(p2.first);
}
});
return
moves;
}
public
static
void
main(String[] args) {
int
n =
4
;
int
x =
2
, y =
2
;
List<Pair<Integer, Integer>> moves = findPossibleMoves(n, x, y);
for
(Pair<Integer, Integer> move : moves) {
System.out.println(
"("
+ move.first +
", "
+ move.second +
")"
);
}
}
}