日期:2014-05-20 浏览次数:20993 次
public static void main(String[] args) throws Exception {
final int size = 10;
final Point startPos = new Point(0, 2);
List<Point> borderPositions = new ArrayList<Point>();
for (int i = size; i-- > 0;) { // Top, from right to left
borderPositions.add(new Point(i, 0));
}
for (int i = 1; i < size; i++) { // Left, from top to bottom
borderPositions.add(new Point(0, i));
}
for (int i = 1; i < size; i++) { // Bottom, from left to right
borderPositions.add(new Point(i, size - 1));
}
for (int i = size - 1; i-- > 1;) { // Right, from bottom to top
borderPositions.add(new Point(size - 1, i));
}
Scanner scanner = new Scanner(System.in);
int index = borderPositions.indexOf(startPos);
System.out.println(startPos);
while (scanner.hasNext()) {
int num = scanner.nextInt();
index += (num % 2 == 0) ? 1 : 3;
index %= borderPositions.size();
System.out.println(borderPositions.get(index));
}
}