ASCII Artical:Shadow-Casting

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)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值