310892: CF1906A. Easy As ABC

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Easy As ABCtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

You are playing a word puzzle. The puzzle starts with a $3$ by $3$ grid, where each cell contains either the letter A, B, or C.

The goal of this puzzle is to find the lexicographically smallest possible word of length $3$. The word can be formed by choosing three different cells where the cell containing the first letter is adjacent to the cell containing the second letter, and the cell containing the second letter is adjacent to the cell containing the third letter.

Two cells are adjacent to each other if they share a border or a corner, as shown in the following illustration. Formally, if $(r, c)$ denotes the cell in the $r$-th row and $c$-th column, then cell $(r, c)$ is adjacent to cell $(r, c + 1)$, $(r - 1, c + 1)$, $(r - 1, c)$, $(r - 1, c - 1)$, $(r, c - 1)$, $(r + 1, c - 1)$, $(r + 1, c)$, and $(r + 1, c + 1)$.

Determine the lexicographically smallest possible word of length $3$ that you can find within the grid.

A string $s$ of length $n$ is lexicographically smaller than string $t$ of the same length if there exists an integer $1 \leq i \leq n$ such that $s_j = t_j$ for all $1 \leq j < i$, and $s_i < t_i$ in alphabetical order. The following illustration shows some examples on some grids and their the lexicographically smallest possible word of length $3$ that you can find within the grids.

Input

Input consists of three lines, each containing three letters, representing the puzzle grid. Each letter in the grid can only be either A, B, or C.

Output

Output the lexicographically smallest possible word of length $3$ that you can find within the grid.

ExamplesInput
BCB
CAC
BCB
Output
ABC
Input
BCB
CCC
CCA
Output
ACB
Input
ACA
CBC
ACA
Output
ABA
Input
ACA
CAC
ACA
Output
AAA
Input
CCC
CBC
CCC
Output
BCC

Output

题目大意:
你正在玩一个单词拼图游戏。拼图从一个3x3的网格开始,每个单元格包含字母A、B或C。目标是找到字典序最小的长度为3的单词。单词可以通过选择三个不同的单元格来形成,其中包含第一个字母的单元格与包含第二个字母的单元格相邻,包含第二个字母的单元格与包含第三个字母的单元格相邻。两个单元格相邻是指它们共享一个边界或一个角。确定在网格中可以找到的字典序最小的长度为3的单词。

输入数据格式:
输入由三行组成,每行包含三个字母,代表拼图网格。网格中的每个字母只能是A、B或C。

输出数据格式:
输出在网格中可以找到的字典序最小的长度为3的单词。

示例:
输入:
```
BCB
CAC
BCB
```
输出:
```
ABC
```

输入:
```
BCB
CCC
CCA
```
输出:
```
ACB
```

输入:
```
ACA
CBC
ACA
```
输出:
```
ABA
```

输入:
```
ACA
CAC
ACA
```
输出:
```
AAA
```

输入:
```
CCC
CBC
CCC
```
输出:
```
BCC
```

请注意,以上示例仅用于说明输入和输出格式,实际答案可能因网格内容而异。题目大意: 你正在玩一个单词拼图游戏。拼图从一个3x3的网格开始,每个单元格包含字母A、B或C。目标是找到字典序最小的长度为3的单词。单词可以通过选择三个不同的单元格来形成,其中包含第一个字母的单元格与包含第二个字母的单元格相邻,包含第二个字母的单元格与包含第三个字母的单元格相邻。两个单元格相邻是指它们共享一个边界或一个角。确定在网格中可以找到的字典序最小的长度为3的单词。 输入数据格式: 输入由三行组成,每行包含三个字母,代表拼图网格。网格中的每个字母只能是A、B或C。 输出数据格式: 输出在网格中可以找到的字典序最小的长度为3的单词。 示例: 输入: ``` BCB CAC BCB ``` 输出: ``` ABC ``` 输入: ``` BCB CCC CCA ``` 输出: ``` ACB ``` 输入: ``` ACA CBC ACA ``` 输出: ``` ABA ``` 输入: ``` ACA CAC ACA ``` 输出: ``` AAA ``` 输入: ``` CCC CBC CCC ``` 输出: ``` BCC ``` 请注意,以上示例仅用于说明输入和输出格式,实际答案可能因网格内容而异。

加入题单

上一题 下一题 算法标签: