To solve this problem, we need to convert a 4x4 grid of numbers into a corresponding grid of letters where each number maps directly to a letter (1→A, 2→B, 3→C, 4→D).
Approach
- Input Reading: Read 4 lines of input, each containing 4 integers.
- Mapping Numbers to Letters: For each integer in the grid, convert it to the corresponding letter using the mapping: 1→A, 2→B, 3→C, 4→D. This can be done using ASCII values where 'A' is 65, so adding (number - 1) to the ASCII value of 'A' gives the correct letter.
- Output: For each row, join the converted letters with spaces and print the result.
Solution Code
for _ in range(4):
nums = list(map(int, input().split()))
letters = [chr(ord('A') + num - 1) for num in nums]
print(' '.join(letters))
Explanation
- Reading Input: The loop reads 4 lines of input, each line split into a list of integers.
- Conversion: Each integer is converted to a letter by calculating the ASCII value. For example, 1 becomes 'A' (65 + 0), 2 becomes 'B' (65 +1), etc.
- Output: Each row of letters is joined with spaces to form the output string, which is then printed.
This approach efficiently maps the numbers to letters and produces the required output in linear time relative to the size of the grid, making it optimal for the given problem constraints.


作者声明:本文包含人工智能生成内容。