Сагура Николай, 392, сев. филиал SetJuggler 3974
Dimitry SetJuggler 3871
t1import syst1import sys
2words = set()2words = set()
3while True:3while True:
4    try:4    try:
5        line = input().strip()5        line = input().strip()
6    except EOFError:6    except EOFError:
7        break7        break
8    if not line:8    if not line:
9        break9        break
10    for word in line.split():10    for word in line.split():
11        words.add(word)11        words.add(word)
12sets = {'ALL': words}12sets = {'ALL': words}
13while True:13while True:
14    try:14    try:
15        line = input().strip()15        line = input().strip()
16    except EOFError:16    except EOFError:
17        break17        break
18    if not line:18    if not line:
19        break19        break
20    tokens = line.split()20    tokens = line.split()
21    if tokens[0] == 'print':21    if tokens[0] == 'print':
22        set_names = tokens[1].split(',')22        set_names = tokens[1].split(',')
23        union = set()23        union = set()
24        for name in set_names:24        for name in set_names:
25            if name in sets:25            if name in sets:
26                union |= sets[name]26                union |= sets[name]
27        print(' '.join(sorted(union)))27        print(' '.join(sorted(union)))
28    elif tokens[0] == 'search':28    elif tokens[0] == 'search':
29        source_sets = tokens[1].split(',')29        source_sets = tokens[1].split(',')
30        union_source = set()30        union_source = set()
31        for name in source_sets:31        for name in source_sets:
32            if name in sets:32            if name in sets:
33                union_source |= sets[name]33                union_source |= sets[name]
34        if tokens[2] == 'where':34        if tokens[2] == 'where':
35            substring = tokens[3]35            substring = tokens[3]
36            to_index = tokens.index('to')36            to_index = tokens.index('to')
37            new_name = tokens[to_index + 1]37            new_name = tokens[to_index + 1]
38            new_set = {w for w in union_source if substring in w}38            new_set = {w for w in union_source if substring in w}
39            sets[new_name] = new_set39            sets[new_name] = new_set
40        elif tokens[2] == 'for':40        elif tokens[2] == 'for':
41            target_sets = tokens[3].split(',')41            target_sets = tokens[3].split(',')
42            union_target = set()42            union_target = set()
43            for name in target_sets:43            for name in target_sets:
44                if name in sets:44                if name in sets:
45                    union_target |= sets[name]45                    union_target |= sets[name]
46            to_index = tokens.index('to')46            to_index = tokens.index('to')
47            new_name = tokens[to_index + 1]47            new_name = tokens[to_index + 1]
48            new_set = union_source & union_target48            new_set = union_source & union_target
49            sets[new_name] = new_set49            sets[new_name] = new_set
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op