-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTravel_Restrictions.py
68 lines (56 loc) · 1.96 KB
/
Travel_Restrictions.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
import sys
def left2right_path(i, j):
return [k for k in range(i, j+1)]
def right2left_path(i, j):
return [k for k in reversed(range(j, i+1))]
def restriction(flight_path):
def country_res(k):
in_res = incoming[k-1]
out_res = outgoing[k-1]
return in_res + out_res
temp = [country_res(k) for k in flight_path]
temp = ''.join(temp)
temp = temp[1:-1]
if len(temp) < 1:
return 'Y'
else:
return temp
def path(i, j):
if i < j:
return left2right_path(i, j)
elif i > j:
return right2left_path(i, j)
else:
return [i]
class Flight():
def __init__(self, country_num, incoming, outgoing):
super().__init__()
self.country_num = country_num
self.incoming = incoming
self.outgoing = outgoing
if __name__ == "__main__":
in_file = open('travel_restrictions_input.txt', 'r')
flight_num = int(in_file.readline())
flight_list = []
for f in range(0, flight_num):
country_num = int(in_file.readline())
incoming = in_file.readline()
outgoing = in_file.readline()
flight_obj = Flight(country_num, incoming, outgoing)
flight_list.append(flight_obj)
out_file = open('travel_restrictions_output.txt', 'w')
for f in range(0, flight_num):
out_file.write('Case #{}:\n'.format(f+1))
country_num = flight_list[f].country_num
incoming = flight_list[f].incoming
outgoing = flight_list[f].outgoing
for i in range(1, country_num + 1):
for j in range(1, country_num+1):
restrict = restriction(path(i, j))
check = 'N' if 'N' in restrict else 'Y'
out_file.write(check)
if f == flight_num - 1 and i == country_num and j == country_num:
continue
else:
out_file.write('\n')
out_file.close()