Given an ASCII art pattern, cast a shadow as if the light source is at top-left corner to make the pattern 3D-like.
Use hyphen (-) for darker shadow, and backtick (`) for lighter one.
Darker shadow is projected by shifting existing pattern 1 character down and 1 character right.
Lighter shadow is projected by shifting existing pattern 2 character down and 2 character right.
Input
Line 1: An integer N for the number of lines of the ASCII art pattern.
Next N lines: Lines of the ASCII art pattern.
Output
The processed pattern, with whitespace at the right trimmed, if any.
Constraints
1 ≤ N ≤ 50
Example
Input
7
# #
# #
# #
#
# #
# #
# #
Output
# #
# # -
# # - `
# - `
# # `
# - #
# - ` #
- ` -
` `
解决方案:
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
n = int(input())
line_11 = []
line_22 = []
lines = []
for i in range(n):
line = input()
lines.append(list(line))
for j in range(len(line)):
if line[j] != ' ':
line_11.append([i+1, j+1])
line_22.append([i+2, j+2])
width = len(lines[n-1])
lines.extend([[' ' for _ in range(width)], [' ' for _ in range(width+1)]])
n += 2
print(lines, file=sys.stderr, flush=True)
print(line_11, file=sys.stderr, flush=True)
print(line_22, file=sys.stderr, flush=True)
for i in line_11:
row, col = i
rlen = len(lines[row])
if col < rlen:
if lines[row][col] == ' ':
lines[row][col] = '-'
else:
lines[row].extend([' ' for _ in range(col-rlen)])
lines[row].append('-')
for i in line_22:
row, col = i
rlen = len(lines[row])
if col < rlen:
if lines[row][col] == ' ':
lines[row][col] = '`'
else:
lines[row].extend([' ' for _ in range(col-rlen)])
lines[row].append('`')
answer = ''
for i in range(n):
if i+1 < n:
answer += ''.join(lines[i]) + '\n'
else:
answer += ''.join(lines[i])
print(answer)