-
Notifications
You must be signed in to change notification settings - Fork 0
/
0520_huawei_1.py
47 lines (43 loc) · 1.02 KB
/
0520_huawei_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
def main():
# input processing
in_list = []
while True:
line = sys.stdin.readline().strip()
if not line:
break
in_list.append(line)
splitter = in_list.pop(0)
n_node = len(in_list)
res = []
tmp = []
isValid = True
for i in range(n_node):
idx, name = in_list[i].split(',')
if not idx.isdigit():
isValid = False
if name == splitter:
if len(tmp) != 0:
res.append(tmp)
tmp = []
continue
tmp.append(in_list[i])
if tmp:
res.append(tmp)
n_group = len(res)
if isValid:
print(n_group)
for i in range(n_group):
if len(res[i]) == 1:
print(res[i])
else:
print("|".join(res[i]))
else:
print(0)
# if __name__ == '__main__':
# inlist = ['*',
# "1,name1",
# "2,name2",
# "3,*",
# "4,name4",
# "5,name5"]