1906A.md (2212B)
1 Source: https://codeforces.com/problemset/problem/1906/A 2 3 A. Easy As ABC 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 1024 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 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. 24 25 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)$. 26 27  28 29 Determine the lexicographically smallest possible word of length $3$ that you can find within the grid. 30 31 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 \lt i$, and $s_i \lt 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. 32 33  34 35 Input 36 37 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. 38 39 Output 40 41 Output the lexicographically smallest possible word of length $3$ that you can find within the grid. 42 43 Examples 44 45 Input 46 47 ``` 48 BCB 49 CAC 50 BCB 51 ``` 52 53 Output 54 55 ``` 56 ABC 57 ``` 58 59 Input 60 61 ``` 62 BCB 63 CCC 64 CCA 65 ``` 66 67 Output 68 69 ``` 70 ACB 71 ``` 72 73 Input 74 75 ``` 76 ACA 77 CBC 78 ACA 79 ``` 80 81 Output 82 83 ``` 84 ABA 85 ``` 86 87 Input 88 89 ``` 90 ACA 91 CAC 92 ACA 93 ``` 94 95 Output 96 97 ``` 98 AAA 99 ``` 100 101 Input 102 103 ``` 104 CCC 105 CBC 106 CCC 107 ``` 108 109 Output 110 111 ``` 112 BCC 113 ```