A. King Moves

Codeforces
IDCF710A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
The only king stands on the standard chess board. You are given his position in format "_cd_", where _c_ is the column from 'a' to 'h' and _d_ is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wiki/King_(chess)). <center>![image](https://espresso.codeforces.com/1a74a03b742b0f0fe2f16293dc7429e30f7a50f4.png) King moves from the position e4</center> ## Input The only line contains the king's position in the format "_cd_", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. ## Output Print the only integer _x_ — the number of moves permitted for the king. [samples]
仅有一个国王位于标准的国际象棋棋盘上。给定他的位置,格式为 "_cd_",其中 #cf_span[c] 是从 'a' 到 'h' 的列,#cf_span[d] 是从 '1' 到 '8' 的行。请计算国王允许的移动步数。 国王的移动方式请参见:https://en.wikipedia.org/wiki/King_(chess)。 仅一行包含国王的位置,格式为 "_cd_",其中 'c' 是从 'a' 到 'h' 的列,'d' 是从 '1' 到 '8' 的行。 请输出一个整数 #cf_span[x] —— 国王允许的移动步数。 ## Input 仅一行包含国王的位置,格式为 "_cd_",其中 'c' 是从 'a' 到 'h' 的列,'d' 是从 '1' 到 '8' 的行。 ## Output 请输出一个整数 #cf_span[x] —— 国王允许的移动步数。 [samples]
**Definitions** Let $ p = (c, r) $ be the king's position, where: - $ c \in \{ \texttt{a}, \texttt{b}, \dots, \texttt{h} \} $ maps to column index $ x \in \{1, 2, \dots, 8\} $ via $ x = \texttt{ord}(c) - \texttt{ord}(\texttt{a}) + 1 $, - $ r \in \{1, 2, \dots, 8\} $ is the row index. **Constraints** $ 1 \le x \le 8 $, $ 1 \le r \le 8 $ **Objective** Compute the number of valid moves for the king, i.e., the number of positions $ (x', r') \in \{1, \dots, 8\}^2 $ such that: - $ |x' - x| \le 1 $, - $ |r' - r| \le 1 $, - $ (x', r') \ne (x, r) $. Let $ N = \left| \left\{ (x', r') \in \mathbb{Z}^2 \,\middle|\, |x' - x| \le 1,\, |r' - r| \le 1,\, (x', r') \ne (x, r),\, 1 \le x' \le 8,\, 1 \le r' \le 8 \right\} \right| $. Output $ N $.
Samples
Input #1
e4
Output #1
8
API Response (JSON)
{
  "problem": {
    "name": "A. King Moves",
    "description": {
      "content": "The only king stands on the standard chess board. You are given his position in format \"_cd_\", where _c_ is the column from 'a' to 'h' and _d_ is the row from '1' to '8'. Find the number of moves perm",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF710A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The only king stands on the standard chess board. You are given his position in format \"_cd_\", where _c_ is the column from 'a' to 'h' and _d_ is the row from '1' to '8'. Find the number of moves perm...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "仅有一个国王位于标准的国际象棋棋盘上。给定他的位置,格式为 \"_cd_\",其中 #cf_span[c] 是从 'a' 到 'h' 的列,#cf_span[d] 是从 '1' 到 '8' 的行。请计算国王允许的移动步数。\n\n国王的移动方式请参见:https://en.wikipedia.org/wiki/King_(chess)。\n\n仅一行包含国王的位置,格式为 \"_cd_\",其中 'c' 是从 '...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ p = (c, r) $ be the king's position, where:  \n- $ c \\in \\{ \\texttt{a}, \\texttt{b}, \\dots, \\texttt{h} \\} $ maps to column index $ x \\in \\{1, 2, \\dots, 8\\} $ via $ x = \\texttt{or...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments