Knights Move

면접 대비

시간 제한1초메모리 제한2048 MB

요약
체스판 위 나이트의 위치가 체스 기보법으로 주어지면, 나이트가 이동할 수 있는 모든 합법적인 칸을 사전순으로 출력한다.
난이도

쉬움10점 중 2점

유형
배열, 구현, 시뮬레이션, 정렬
정답자
아직 제출이 없습니다

문제

Before we get into the problem, let's go over algebraic notation in chess. Algebraic notation refers to the "names" of the squares on a chessboard. Starting from left to right (from white's perspective), the columns are named a--h. The rows are then named 11--88 in increasing order (again from white's perspective). Each square's "name" is the column letter followed by the row number of that particular square.

In chess, a knight's move is unique. It may move two squares horizontally and one square vertically, or two squares vertically and one square horizontally (with both forming the shape of an L). For example, a knight on d3 can move to c1, b2, b4, c5, e5, f4, f2, and e1.

Your task is as follows: given the position of a knight on a chessboard in algebraic notation, output all of the knight's possible moves.

입력

The first (and only) line of input is the location of the knight in algebraic notation. It is guaranteed that it will be a valid square on an 8×88 \times 8 chessboard.

출력

Output all of the knight's possible moves in lexicographic order, with each square on its own line. Lexicographic order is a generalization of alphabetical order that means c1 comes before d1, a1 comes before a2, etc.

예제2

  1. 예제 1

    입력
    a1
    
    예상 출력
    b3
    c2
    
  2. 예제 2

    입력
    d3
    
    예상 출력
    b2
    b4
    c1
    c5
    e1
    e5
    f2
    f4