Сагдиев Айрат, 321 группа BoxDrawing 11376
s02220725 BoxDrawing 8635
t1def split_words(words, content_width):t1def split_words(words, content_width):
2    lines = []2    lines = []
3    cur = []3    cur = []
4    cur_len = 04    cur_len = 0
5    for w in words:5    for w in words:
6        needed = len(w) + (1 if cur else 0)6        needed = len(w) + (1 if cur else 0)
7        if cur_len + needed > content_width:7        if cur_len + needed > content_width:
8            lines.append(cur)8            lines.append(cur)
9            cur = [w]9            cur = [w]
10            cur_len = len(w)10            cur_len = len(w)
11        else:11        else:
12            if cur:12            if cur:
13                cur_len += 113                cur_len += 1
14            cur.append(w)14            cur.append(w)
15            cur_len += len(w)15            cur_len += len(w)
16    if cur:16    if cur:
17        lines.append(cur)17        lines.append(cur)
18    return lines18    return lines
1919
20def calculate_column_widths(line, content_width):20def calculate_column_widths(line, content_width):
21    n = len(line)21    n = len(line)
22    total_chars = sum((len(word) for word in line))22    total_chars = sum((len(word) for word in line))
23    extra = content_width - (total_chars + (n - 1))23    extra = content_width - (total_chars + (n - 1))
24    if extra < 0:24    if extra < 0:
25        extra = 025        extra = 0
26    widths = [len(word) for word in line]26    widths = [len(word) for word in line]
27    widths[-1] += extra27    widths[-1] += extra
28    return widths28    return widths
2929
30def calc_real_edges(widths):30def calc_real_edges(widths):
31    edges = set()31    edges = set()
32    pos = 132    pos = 1
33    for w in widths:33    for w in widths:
34        pos += w34        pos += w
35        edges.add(pos)35        edges.add(pos)
36        pos += 136        pos += 1
37    last = pos - 137    last = pos - 1
38    if last in edges:38    if last in edges:
39        edges.remove(last)39        edges.remove(last)
40    return edges40    return edges
4141
42def draw_line_top(widths, TL, T_JOIN, TR, H):42def draw_line_top(widths, TL, T_JOIN, TR, H):
43    s = TL43    s = TL
44    for w in widths[:-1]:44    for w in widths[:-1]:
45        s += H * w + T_JOIN45        s += H * w + T_JOIN
46    s += H * widths[-1] + TR46    s += H * widths[-1] + TR
47    return s47    return s
4848
49def draw_line_bottom(widths, BL, B_JOIN, BR, H):49def draw_line_bottom(widths, BL, B_JOIN, BR, H):
50    s = BL50    s = BL
51    for w in widths[:-1]:51    for w in widths[:-1]:
52        s += H * w + B_JOIN52        s += H * w + B_JOIN
53    s += H * widths[-1] + BR53    s += H * widths[-1] + BR
54    return s54    return s
5555
56def draw_text_line(words, widths, V):56def draw_text_line(words, widths, V):
57    s = V57    s = V
58    for i, (word, width) in enumerate(zip(words, widths)):58    for i, (word, width) in enumerate(zip(words, widths)):
59        s += word.ljust(width)59        s += word.ljust(width)
60        s += V60        s += V
61    return s61    return s
6262
63def draw_middle_line(upper, lower, L_JOIN, R_JOIN, C_JOIN, B_JOIN, T_JOI63def draw_middle_line(upper, lower, L_JOIN, R_JOIN, C_JOIN, B_JOIN, T_JOI
>N, H):>N, H):
64    up_edges = calc_real_edges(upper)64    up_edges = calc_real_edges(upper)
65    low_edges = calc_real_edges(lower)65    low_edges = calc_real_edges(lower)
66    width_u = 1 + sum(upper) + len(upper)66    width_u = 1 + sum(upper) + len(upper)
67    width_l = 1 + sum(lower) + len(lower)67    width_l = 1 + sum(lower) + len(lower)
68    total = max(width_u, width_l) - 168    total = max(width_u, width_l) - 1
69    split_points = sorted(up_edges | low_edges)69    split_points = sorted(up_edges | low_edges)
70    points = [0] + split_points + [total]70    points = [0] + split_points + [total]
71    line = L_JOIN71    line = L_JOIN
72    for i in range(len(points) - 1):72    for i in range(len(points) - 1):
73        left = points[i]73        left = points[i]
74        right = points[i + 1]74        right = points[i + 1]
75        seg = right - left - 175        seg = right - left - 1
76        if seg > 0:76        if seg > 0:
77            line += H * seg77            line += H * seg
78        if right == total:78        if right == total:
79            break79            break
80        up = right in up_edges80        up = right in up_edges
81        lo = right in low_edges81        lo = right in low_edges
82        if up and lo:82        if up and lo:
83            line += C_JOIN83            line += C_JOIN
84        elif up:84        elif up:
85            line += B_JOIN85            line += B_JOIN
86        elif lo:86        elif lo:
87            line += T_JOIN87            line += T_JOIN
88        else:88        else:
89            line += H89            line += H
90    line += R_JOIN90    line += R_JOIN
91    return line91    return line
92text = input().rstrip()92text = input().rstrip()
93w, vt, ht = input().split()93w, vt, ht = input().split()
94width = int(w)94width = int(w)
95content_width = width - 295content_width = width - 2
96vt = vt.upper()96vt = vt.upper()
97ht = ht.upper()97ht = ht.upper()
98if vt == 'LIGHT' and ht == 'LIGHT':98if vt == 'LIGHT' and ht == 'LIGHT':
99    H = '─'99    H = '─'
100    V = '│'100    V = '│'
101    TL, T_JOIN, TR = ('┌', '┬', '┐')101    TL, T_JOIN, TR = ('┌', '┬', '┐')
102    L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤')102    L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤')
103    BL, B_JOIN, BR = ('└', '┴', '┘')103    BL, B_JOIN, BR = ('└', '┴', '┘')
104elif vt == 'LIGHT' and ht == 'HEAVY':104elif vt == 'LIGHT' and ht == 'HEAVY':
105    H = '━'105    H = '━'
106    V = '│'106    V = '│'
107    TL, T_JOIN, TR = ('┍', '┯', '┑')107    TL, T_JOIN, TR = ('┍', '┯', '┑')
108    L_JOIN, C_JOIN, R_JOIN = ('┝', '┿', '┥')108    L_JOIN, C_JOIN, R_JOIN = ('┝', '┿', '┥')
109    BL, B_JOIN, BR = ('┕', '┷', '┙')109    BL, B_JOIN, BR = ('┕', '┷', '┙')
110elif vt == 'HEAVY' and ht == 'LIGHT':110elif vt == 'HEAVY' and ht == 'LIGHT':
111    H = '─'111    H = '─'
112    V = '┃'112    V = '┃'
113    TL, T_JOIN, TR = ('┎', '┰', '┒')113    TL, T_JOIN, TR = ('┎', '┰', '┒')
114    L_JOIN, C_JOIN, R_JOIN = ('┠', '╂', '┨')114    L_JOIN, C_JOIN, R_JOIN = ('┠', '╂', '┨')
115    BL, B_JOIN, BR = ('┖', '┸', '┚')115    BL, B_JOIN, BR = ('┖', '┸', '┚')
116elif vt == 'HEAVY' and ht == 'HEAVY':116elif vt == 'HEAVY' and ht == 'HEAVY':
117    H = '━'117    H = '━'
118    V = '┃'118    V = '┃'
119    TL, T_JOIN, TR = ('┏', '┳', '┓')119    TL, T_JOIN, TR = ('┏', '┳', '┓')
120    L_JOIN, C_JOIN, R_JOIN = ('┣', '╋', '┫')120    L_JOIN, C_JOIN, R_JOIN = ('┣', '╋', '┫')
121    BL, B_JOIN, BR = ('┗', '┻', '┛')121    BL, B_JOIN, BR = ('┗', '┻', '┛')
122else:122else:
123    H = '─'123    H = '─'
124    V = '│'124    V = '│'
125    TL, T_JOIN, TR = ('┌', '┬', '┐')125    TL, T_JOIN, TR = ('┌', '┬', '┐')
126    L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤')126    L_JOIN, C_JOIN, R_JOIN = ('├', '┼', '┤')
127    BL, B_JOIN, BR = ('└', '┴', '┘')127    BL, B_JOIN, BR = ('└', '┴', '┘')
128words = text.split()128words = text.split()
129lines = split_words(words, content_width)129lines = split_words(words, content_width)
130W = [calculate_column_widths(line, content_width) for line in lines]130W = [calculate_column_widths(line, content_width) for line in lines]
131print(draw_line_top(W[0], TL, T_JOIN, TR, H))131print(draw_line_top(W[0], TL, T_JOIN, TR, H))
132for i in range(len(lines)):132for i in range(len(lines)):
133    print(draw_text_line(lines[i], W[i], V))133    print(draw_text_line(lines[i], W[i], V))
134    if i + 1 < len(lines):134    if i + 1 < len(lines):
135        print(draw_middle_line(W[i], W[i + 1], L_JOIN, R_JOIN, C_JOIN, B135        print(draw_middle_line(W[i], W[i + 1], L_JOIN, R_JOIN, C_JOIN, B
>_JOIN, T_JOIN, H))>_JOIN, T_JOIN, H))
136print(draw_line_bottom(W[-1], BL, B_JOIN, BR, H))136print(draw_line_bottom(W[-1], BL, B_JOIN, BR, H))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op