| UFPE Starters Final Try-Outs 2026 |
|---|
| Закончено |
Ftg, after losing several chess matches against Yrei, decides to develop a chess engine to assist him in his games. To do so, the engine must be able to receive a board position and indicate the best move to be played. After doing some research, Ftg discovered that the best way to share chess positions is by using the FEN (Forsyth-Edwards Notation) format, which works as follows: FEN describes the board from the 8th to the 1st row, using uppercase letters for white pieces and lowercase for black (e.g., P = White Pawn, n = Black Knight). Consecutive empty squares are represented by numbers (1 to 8), and each row is separated by a forward slash (/). The notation flows from left to right (file A to H), always totaling 8 units per line.

Note that both the FEN notation and the board ranks are read from 8 to 1.
Ftg has great programming skills and could code this quickly. However, Yrei has just challenged him to a match, and he will need to focus entirely on that. Could you help Ftg create a chess position converter for the FEN format?
The input consists of exactly 8 lines, each containing exactly 8 characters. These lines represent the current state of the chessboard from the 8th row to the 1st row.
An empty square is represented by a dot (.). White pieces are represented by uppercase letters (P, N, B, R, Q, K), and black pieces are represented by lowercase letters (p, n, b, r, q, k).
Output a single string — the FEN (Forsyth-Edwards Notation) representation of the given board position as described in the legend.
rnbqkbnrpppppppp................................PPPPPPPPRNBQKBNR
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
r.bk...rp..pBpNpn....n...p.NP..P......P....P....P.P.K...q.....b.
r1bk3r/p2pBpNp/n4n2/1p1NP2P/6P1/3P4/P1P1K3/q5b1
R......k..R...........R.pp.Ppp..........Pn..B.Pr....KP..........
R6k/2R5/6R1/pp1Ppp2/8/Pn2B1Pr/4KP2/8
The first sample shows the standard starting position of a chess game. The first two rows are printed exactly as they are. The next four rows consist entirely of empty squares, so each row is converted to the number 8. The final two rows are printed exactly as they are.
In the second sample, the first row r.bk...r contains two groups of empty squares: one dot between r and b becomes 1, and three dots between k and r become 3, resulting in r1bk3r.
The third sample is the image.
| Название |
|---|


