-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_state.py
83 lines (62 loc) · 1.3 KB
/
process_state.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
there are totally 5 states A,B,C,D,E
all processes are initially in state A
the state transitions 'AB 2' implies that process 2 changes from state A to B
find the processes in each state
input format :
# of processes
# of transitions
transitions
input:
10
8
AB 2
AB 4
AB 5
AD 6
AD 7
AE 10
DE 6
BD 5
"""
def process(list1, p, n):
d={'A':[],'B':[],'C':[],'D':[],'E':[]}
lookup={}
for each in list1:
if(each[3]=='1' and each[4]=='0'):
if 10 not in lookup.keys():
lookup[10]=each[1]
d[each[1]].append(10)
continue
else:
temp=lookup[10]
d[temp].remove(10)
lookup[10]=each[1]
d[each[1]].append(10)
continue
c=int(each[3])
if c not in lookup.keys():
lookup[c]=each[1]
d[each[1]].append(c)
else:
temp=lookup[c]
d[temp].remove(c)
lookup[c]=each[1]
d[each[1]].append(c)
lis=lookup.keys()
processes=[i for i in range(1,p+1)]
not_alloted=list(set(processes)-set(lis))
for i in not_alloted:
d['A'].append(i)
for each in d.keys():
print('\n',each,end="")
tmp=sorted(d[each])
for i in tmp:
print(' ',i,end="")
p=int(input())
n=int(input())
lis=[]
for i in range(n):
string=input()
lis.append(string)
process(lis,p,n)