72 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# input parse
rows, columns = input().split(" ")
rows = int(rows)
columns = int(columns)
matrix = [["." for _ in range(columns + 2)] for _ in range(rows)]
for row in range(rows):
user_input = input().split(" ")
# 确保用户输入的数据长度与列数匹配
if len(user_input) != columns:
print("Error: Incorrect number of columns entered.")
continue
# 在第一个点和最后一个点之间插入用户输入
matrix[row][1:-1] = user_input
# Subtask 1 (30 points)矩阵中仅有数字1
# Subtask 2 (30 points):矩阵中不含有数字 1 和 4
# Subtask 3 (40 points):无特殊性质。
count1 = 0
count2 = 0
count3 = 0
result = ""
number_dict = {
"050": "1",
"434": "2",
"335": "3",
"315": "4",
"534": "6",
"115": "7",
"535": "8",
"435": "9",
"525": "0",
}
first_row = 0
for column in range(columns):
for row in range(rows):
if matrix[row][column] == "#":
count1 += 1
if matrix[row][column + 1] == "#":
count2 += 1
if matrix[row][column + 2] == "#":
count3 += 1
number = str(count1) + str(count2) + str(count3)
count1 = 0
count2 = 0
count3 = 0
if number in number_dict.keys():
if number == "434":
for row in range(rows):
try:
if matrix[row][column] == "#" and matrix[row + 1][column] == ".":
result += "2"
break
elif matrix[row][column] == "#" and matrix[row + 1][column] == "#":
result += "5"
break
else:
pass
except IndexError:
pass
else:
result += number_dict[number]
print(result)