final bijna
[ar1516.git] / src / a2.py
1 #!/usr/bin/env python3
2 import sys
3 import re
4
5 comps = {}
6
7 for line in sys.stdin:
8 match = re.match('\(= c(?P<c>\d+)(?P<t>.) (?P<v>\d+)\)', line)
9 if match:
10 c = int(match.group('c'))
11 comps[c] = comps.get(c, {})
12 comps[c][match.group('t')] = int(match.group('v'))
13
14 maxx = max(c['x']+c['w'] for c in comps.values())
15 maxy = max(c['y']+c['h'] for c in comps.values())
16 print('$\\begin{{array}}{{|l|{}|}}'.format('@{}c@{}'*maxx))
17 print('\t\\toprule')
18 print('\t & {}\\\\'.format(
19 ' & '.join(map(str, range(1, maxx+1)))))
20 print('\t\\midrule')
21 for y in range(1, maxy+1):
22 print('\t{} & '.format(y), end='')
23 for x in range(1, maxx+1):
24 cs = [c for c in comps if
25 comps[c]['y'] + comps[c]['h'] >= y and comps[c]['y'] <= y and
26 comps[c]['x'] + comps[c]['w'] >= x and comps[c]['x'] <= x]
27 if cs:
28 print('\\hspace{{.5mm}}{}\\hspace{{.5mm}}'.format(
29 '\mathbf{{{}}}'.format(cs[0]) if cs[0] <= 3 else cs[0]), end='')
30 if x != maxx:
31 print(' & ', end='')
32 print('\\\\')
33
34 print('\t\\bottomrule')
35 print('\\end{array}$')