final bijna
[ar1516.git] / src / a3.py
1 #!/usr/bin/env python3
2 import sys
3 import re
4
5 schedule = {}
6 jobs = set()
7 levels = {}
8 for line in sys.stdin:
9 match = re.match('\(= j(?P<j>\d+) (?P<x>\d+)\)', line)
10 if match:
11 j = int(match.group('j'))
12 x = int(match.group('x'))
13 jobs.add(j)
14 for t in range(x, x+j):
15 schedule[t] = schedule.get(t, [])
16 schedule[t].append(j)
17
18 tmax = max(schedule)+1
19 levels = {j:max(schedule[t].index(j) if j in schedule[t] else 0
20 for t in range(1, tmax)) for j in jobs}
21 schedule = {k:sorted(v) for k,v in schedule.items()}
22 depth = max(map(len, schedule.values()))
23 print('$\\begin{{array}}{{|{}}}'.format('@{}c@{}|'*tmax))
24 print('\t\\toprule')
25 print('\t{}\\\\'.format(' & '.join(map(str, range(1, tmax)))))
26 print('\t\\midrule')
27 for d in range(depth):
28 print('\t', end='')
29 for t in range(1, tmax):
30 cj = [j for j in jobs if levels[j] == d and j in schedule[t]]
31 if cj:
32 print('\\hspace{{.5mm}}{}\\hspace{{.5mm}}'.format(
33 '\\mathbf{{{}}}'.format(cj[0])
34 if cj[0] in [5, 7, 10] else cj[0]), end='')
35 if t != tmax-1:
36 print(' & ', end='')
37 print('\\\\')
38 print('\t\\bottomrule')
39 print('\\end{array}$')