-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstpar.py
37 lines (35 loc) · 1.05 KB
/
stpar.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
while True:
numberOfTrucks = int( raw_input() )
if not numberOfTrucks:
break
truckOrder = raw_input()
truckOrder = map( int, truckOrder.split() ) # By default, split() is equivalent to split( ' ' )
if numberOfTrucks == 1:
print "yes"
else:
sideStreet = list() # Stack
expected = 1
for truck in truckOrder:
if truck != expected:
sideStreet.append( truck )
else:
expected = expected + 1
while sideStreet:
top = sideStreet.pop()
if top == expected:
expected = expected + 1
else:
sideStreet.append( top )
break
flag = 0
while sideStreet:
top = sideStreet.pop()
if top == expected:
expected = expected + 1
else:
flag = 1
break
if flag:
print "no"
else:
print "yes"