상세 컨텐츠

본문 제목

SW Expert Academy 특이한 자석

Python/문제풀이 (삼성 A형 대비)

by 코딩하는 낙타 2020. 2. 18. 18:28

본문

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIeV9sKkcoDFAVH&categoryId=AWIeV9sKkcoDFAVH&categoryType=CODE

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

내 풀이:

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
def rot(idx, dir):
    rot_TF = [False] * 4
    rot_TF[idx-1= True
 
    for i in range(idx-13):
        if mag[i][2== mag[i+1][-2]:
            break
        else:
            rot_TF[i+1= True
 
    for i in range(idx-10-1):
        if mag[i][-2== mag[i-1][2]:
            break
        else:
            rot_TF[i-1= True
 
    d = [0* 4
    for i in range(4):
        if (i-idx-1) % 2 == 0:
            d[i] = dir
        else:
            d[i] = -dir
 
    for i in range(4):
        if rot_TF[i]:
            if d[i] == 1:
                a = mag[i].pop()
                mag[i].insert(0, a)
                
            else:
                a = mag[i].pop(0)
                mag[i].append(a)
 
 
= int(input())
for case in range(1, T+1):
    K = int(input())
    mag = []
 
    for _ in range(4):
        mag.append(list(map(int,input().split())))
 
    for _ in range(K):
        idx, dir = map(int,input().split())
        rot(idx, dir)
 
    ans = 0
    for i in range(4):
        if mag[i][0== 1:
            ans += 2 ** i
 
    print("#%d"%(case), ans)
 

Python3, 193ms

문제의 조건에 대한 코딩만 잘 해주면 되는 문제인데 이 문제를 옛날에 풀었다가 이번에 다시 풀면서 코딩을 깔끔하게 하는 실력이 많이 늘었다는 것을 새삼 느낄 수 있었다.

관련글 더보기

댓글 영역