File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ # # idea : 시계방향으로 흐르면 popleft 후 append, 반시계방향으로 흐르면 pop 후 appendleft
2
+
3
+ import sys
4
+ from collections import deque
5
+ input = sys .stdin .readline
6
+
7
+ li = []
8
+ for _ in range (4 ):
9
+ li .append (deque (input ().rstrip ()))
10
+
11
+
12
+ k = int (input ())
13
+ command = [] # num, dir
14
+ for i in range (k ):
15
+ command .append (list (map (int , input ().split ())))
16
+
17
+ # 왼쪽 톱니바퀴 확인
18
+ def rotate_left (num , dir ):
19
+ if num < 0 : # 왼쪽 끝까지 간 경우
20
+ return
21
+ if li [num ][2 ] != li [num + 1 ][6 ]:
22
+ rotate_left (num - 1 , - dir )
23
+ li [num ].rotate (dir )
24
+
25
+ #오른쪽 톱니바퀴 확인
26
+ def rotate_right (num , dir ):
27
+ if num > 3 : # 오른쪽 끝까지 간 경우
28
+ return
29
+ if li [num ][6 ] != li [num - 1 ][2 ]:
30
+ rotate_right (num + 1 , - dir )
31
+ li [num ].rotate (dir )
32
+
33
+ for i in range (k ):
34
+ num = command [i ][0 ] - 1
35
+ dir = command [i ][1 ]
36
+
37
+ rotate_left (num - 1 , - dir ) # 인접한 바퀴는 해당 바퀴랑 반대방향을 돌아야함. 함수 안에서 돌아야하는지 아닌지를 판단.
38
+ rotate_right (num + 1 , - dir )
39
+ # 기존의 톱니바퀴를 회전시키는 작업
40
+ li [num ].rotate (dir )
41
+
42
+ answer = 0
43
+
44
+ if li [0 ][0 ] == '1' :
45
+ answer += 1
46
+ if li [1 ][0 ] == '1' :
47
+ answer += 2
48
+ if li [2 ][0 ] == '1' :
49
+ answer += 4
50
+ if li [3 ][0 ] == '1' :
51
+ answer += 8
52
+
53
+ print (answer )
54
+
You can’t perform that action at this time.
0 commit comments