| t | def split_words(words, content_width): | t | def split_words(words, content_width): |
| lines = [] | | lines = [] |
| cur = [] | | cur = [] |
| cur_len = 0 | | cur_len = 0 |
| for w in words: | | for w in words: |
| needed = len(w) + (1 if cur else 0) | | needed = len(w) + (1 if cur else 0) |
| if cur_len + needed > content_width: | | if cur_len + needed > content_width: |
| lines.append(cur) | | lines.append(cur) |
| cur = [w] | | cur = [w] |
| cur_len = len(w) | | cur_len = len(w) |
| else: | | else: |
| if cur: | | if cur: |
| cur_len += 1 | | cur_len += 1 |
| cur.append(w) | | cur.append(w) |
| cur_len += len(w) | | cur_len += len(w) |
| if cur: | | if cur: |
| lines.append(cur) | | lines.append(cur) |
| return lines | | return lines |
| | | |
| def calculate_column_widths(line, content_width): | | def calculate_column_widths(line, content_width): |
| n = len(line) | | n = len(line) |
| total_chars = sum((len(word) for word in line)) | | total_chars = sum((len(word) for word in line)) |
| extra = content_width - (total_chars + (n - 1)) | | extra = content_width - (total_chars + (n - 1)) |
| if extra < 0: | | if extra < 0: |
| extra = 0 | | extra = 0 |
| widths = [len(word) for word in line] | | widths = [len(word) for word in line] |
| widths[-1] += extra | | widths[-1] += extra |
| return widths | | return widths |
| | | |
| def calc_real_edges(widths): | | def calc_real_edges(widths): |
| edges = set() | | edges = set() |
| pos = 1 | | pos = 1 |
| for w in widths: | | for w in widths: |
| pos += w | | pos += w |
| edges.add(pos) | | edges.add(pos) |
| pos += 1 | | pos += 1 |
| last = pos - 1 | | last = pos - 1 |
| if last in edges: | | if last in edges: |
| edges.remove(last) | | edges.remove(last) |
| return edges | | return edges |
| | | |
| def draw_line_top(widths, TL, T_JOIN, TR, H): | | def draw_line_top(widths, TL, T_JOIN, TR, H): |
| s = TL | | s = TL |
| for w in widths[:-1]: | | for w in widths[:-1]: |
| s += H * w + T_JOIN | | s += H * w + T_JOIN |
| s += H * widths[-1] + TR | | s += H * widths[-1] + TR |
| return s | | return s |
| | | |
| def draw_line_bottom(widths, BL, B_JOIN, BR, H): | | def draw_line_bottom(widths, BL, B_JOIN, BR, H): |
| s = BL | | s = BL |
| for w in widths[:-1]: | | for w in widths[:-1]: |
| s += H * w + B_JOIN | | s += H * w + B_JOIN |
| s += H * widths[-1] + BR | | s += H * widths[-1] + BR |
| return s | | return s |
| | | |
| def draw_text_line(words, widths, V): | | def draw_text_line(words, widths, V): |
| s = V | | s = V |
| for i, (word, width) in enumerate(zip(words, widths)): | | for i, (word, width) in enumerate(zip(words, widths)): |
| s += word.ljust(width) | | s += word.ljust(width) |
| s += V | | s += V |
| return s | | return s |
| | | |
| def draw_middle_line(upper, lower, L_JOIN, R_JOIN, C_JOIN, B_JOIN, T_JOI | | def draw_middle_line(upper, lower, L_JOIN, R_JOIN, C_JOIN, B_JOIN, T_JOI |
| N, H): | | N, H): |
| up_edges = calc_real_edges(upper) | | up_edges = calc_real_edges(upper) |
| low_edges = calc_real_edges(lower) | | low_edges = calc_real_edges(lower) |
| width_u = 1 + sum(upper) + len(upper) | | width_u = 1 + sum(upper) + len(upper) |
| width_l = 1 + sum(lower) + len(lower) | | width_l = 1 + sum(lower) + len(lower) |
| total = max(width_u, width_l) - 1 | | total = max(width_u, width_l) - 1 |
| split_points = sorted(up_edges | low_edges) | | split_points = sorted(up_edges | low_edges) |
| points = [0] + split_points + [total] | | points = [0] + split_points + [total] |
| line = L_JOIN | | line = L_JOIN |
| for i in range(len(points) - 1): | | for i in range(len(points) - 1): |
| left = points[i] | | left = points[i] |
| right = points[i + 1] | | right = points[i + 1] |
| seg = right - left - 1 | | seg = right - left - 1 |
| if seg > 0: | | if seg > 0: |
| line += H * seg | | line += H * seg |
| if right == total: | | if right == total: |
| break | | break |
| up = right in up_edges | | up = right in up_edges |
| lo = right in low_edges | | lo = right in low_edges |
| if up and lo: | | if up and lo: |
| line += C_JOIN | | line += C_JOIN |
| elif up: | | elif up: |
| line += B_JOIN | | line += B_JOIN |
| elif lo: | | elif lo: |
| line += T_JOIN | | line += T_JOIN |
| else: | | else: |
| line += H | | line += H |
| line += R_JOIN | | line += R_JOIN |
| return line | | return line |
| text = input().rstrip() | | text = input().rstrip() |
| w, vt, ht = input().split() | | w, vt, ht = input().split() |
| width = int(w) | | width = int(w) |
| content_width = width - 2 | | content_width = width - 2 |
| vt = vt.upper() | | vt = vt.upper() |
| ht = ht.upper() | | ht = ht.upper() |
| if vt == 'LIGHT' and ht == 'LIGHT': | | if vt == 'LIGHT' and ht == 'LIGHT': |
| H = '─' | | H = '─' |
| V = '│' | | V = '│' |
| TL, T_JOIN, TR = ('┌', '┬', '┐') | | TL, T_JOIN, TR = ('┌', '┬', '┐') |
| L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤') | | L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤') |
| BL, B_JOIN, BR = ('└', '┴', '┘') | | BL, B_JOIN, BR = ('└', '┴', '┘') |
| elif vt == 'LIGHT' and ht == 'HEAVY': | | elif vt == 'LIGHT' and ht == 'HEAVY': |
| H = '━' | | H = '━' |
| V = '│' | | V = '│' |
| TL, T_JOIN, TR = ('┍', '┯', '┑') | | TL, T_JOIN, TR = ('┍', '┯', '┑') |
| L_JOIN, C_JOIN, R_JOIN = ('┝', '┿', '┥') | | L_JOIN, C_JOIN, R_JOIN = ('┝', '┿', '┥') |
| BL, B_JOIN, BR = ('┕', '┷', '┙') | | BL, B_JOIN, BR = ('┕', '┷', '┙') |
| elif vt == 'HEAVY' and ht == 'LIGHT': | | elif vt == 'HEAVY' and ht == 'LIGHT': |
| H = '─' | | H = '─' |
| V = '┃' | | V = '┃' |
| TL, T_JOIN, TR = ('┎', '┰', '┒') | | TL, T_JOIN, TR = ('┎', '┰', '┒') |
| L_JOIN, C_JOIN, R_JOIN = ('┠', '╂', '┨') | | L_JOIN, C_JOIN, R_JOIN = ('┠', '╂', '┨') |
| BL, B_JOIN, BR = ('┖', '┸', '┚') | | BL, B_JOIN, BR = ('┖', '┸', '┚') |
| elif vt == 'HEAVY' and ht == 'HEAVY': | | elif vt == 'HEAVY' and ht == 'HEAVY': |
| H = '━' | | H = '━' |
| V = '┃' | | V = '┃' |
| TL, T_JOIN, TR = ('┏', '┳', '┓') | | TL, T_JOIN, TR = ('┏', '┳', '┓') |
| L_JOIN, C_JOIN, R_JOIN = ('┣', '╋', '┫') | | L_JOIN, C_JOIN, R_JOIN = ('┣', '╋', '┫') |
| BL, B_JOIN, BR = ('┗', '┻', '┛') | | BL, B_JOIN, BR = ('┗', '┻', '┛') |
| else: | | else: |
| H = '─' | | H = '─' |
| V = '│' | | V = '│' |
| TL, T_JOIN, TR = ('┌', '┬', '┐') | | TL, T_JOIN, TR = ('┌', '┬', '┐') |
| L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤') | | L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤') |
| BL, B_JOIN, BR = ('└', '┴', '┘') | | BL, B_JOIN, BR = ('└', '┴', '┘') |
| words = text.split() | | words = text.split() |
| lines = split_words(words, content_width) | | lines = split_words(words, content_width) |
| W = [calculate_column_widths(line, content_width) for line in lines] | | W = [calculate_column_widths(line, content_width) for line in lines] |
| print(draw_line_top(W[0], TL, T_JOIN, TR, H)) | | print(draw_line_top(W[0], TL, T_JOIN, TR, H)) |
| for i in range(len(lines)): | | for i in range(len(lines)): |
| print(draw_text_line(lines[i], W[i], V)) | | print(draw_text_line(lines[i], W[i], V)) |
| if i + 1 < len(lines): | | if i + 1 < len(lines): |
| print(draw_middle_line(W[i], W[i + 1], L_JOIN, R_JOIN, C_JOIN, B | | print(draw_middle_line(W[i], W[i + 1], L_JOIN, R_JOIN, C_JOIN, B |
| _JOIN, T_JOIN, H)) | | _JOIN, T_JOIN, H)) |
| print(draw_line_bottom(W[-1], BL, B_JOIN, BR, H)) | | print(draw_line_bottom(W[-1], BL, B_JOIN, BR, H)) |