Programming contests

ILBPM9987L Informatikai versenyfeladatok, 2023. ősz

November 17, 2023, 8:00 PM – January 31, 2024, 11:59 PM

Chessboard in FEN

In FEN (Forsyth–Edwards Notation), a chessboard is described as follows:

  • The board content is specified starting with the top row and ending with the bottom row.
  • Character “/” is used to separate data of adjacent rows.
  • Each row is specified from left to right.
  • White pieces are identified by uppercase piece letters: PNBRQK.
  • Black pieces are identified by lowercase piece letters: pnbrqk.
  • Empty squares are represented by the numbers one through eight.
  • A number used represents the count of contiguous empty squares along a row.
  • In each row, the sum of the numbers and the number of characters must be equal to 8.

For example,

5k1r/2q3p1/p3p2p/1B3p1Q/n4P2/6P1/bbP2N1P/1K1RR3

is the FEN notation description of the following chessboard:

The chessboard of the beginning of a chess game is described in FEN as:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR

Your task is simple: given a chessboard description in FEN notation, you are asked to compute the number of unoccupied squares on the board which are not attacked by any piece.

Input Specification

The input is a sequence of lines, each line containing the FEN description of a chessboard. Note that the description does not necessarily give a legal chess position. Input lines do not contain whitespaces.

Output Specification

For each line of input, output one line containing an integer which gives the number of unoccupied squares which are not attacked.

Sample Input

  1. 5k1r/2q3p1/p3p2p/1B3p1Q/n4P2/6P1/bbP2N1P/1K1RR3
  2. rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
download as text file

Output for Sample Input

  1. 3
  2. 16
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024