The Connect Four Game
Archiviert 2 years ago
L
ᛉ
The Connect Four game
Description
This task is based on the popular 2‐players Connect Four game, also known as Connect 4, Four Up, Plot Four, Find
Four etc. For more information about this game, please refer to Wikipedia. In this task, we will not implement
the game as it is played (i.e. alternatively piling up the tokens from the bottom), but we simply consider that all
tokens (of red or yellow color) are already placed in a square grid of size N × N and that we must simply find
out if there are at least 4 connected tokens of one color in a row, a column or diagonally. The number of tokens
of each color is irrelevant in this task. The result of the program depends on the layout of the tokens. If there
are excusively at least 4 connected tokens of one color, the output is that color. If there are at least 4 connected
tokens for both red and yellow, or if there are no 4 connected tokens of one color at all, the output is NOPE (see
execution examples).
Task
Based on the input data, write a program which determines the correct output according to the token layout.
Constraints
• N ∈ N, 4 ≤ N ≤ 20
Input and output of program
Input data
The first line indicates the square grid size N.
The next N lines indicate the colors of the tokens in the grid, row by row. The upper‐case letter R stands for a
red token, the letter Y stands for a yellow token
Output data
The text RED, YELLOW or NOPE, according to the token layout
Execution example
Input 1
6
RYYYRY
RYRRYY
YRYRYY
RRYRRR
RYRRYY
YRRYYR
Output 1
RED
Input 2
5
YRYRY
RYRYY
YYRYY
RYYYR
YRYRY
Output 2
NOPE
Input 3
5
YRYRY
YYRYY
RRYRR
YYYYY
RRRRR
Output 3
NOPE
Input 4
7
RRYYRYR
YRYRYRY
YRYYYRY
RYRYYYR
RYYRRYY
YRRYYRY
YRRRRYR
Output 4
NOPE
