문제풀이/SW Expert Academy 47

[SWEA][D2] 1948. 날짜 계산기 (파이썬/Python)

t = int(input()) #달과 날짜를 묶어서 딕셔너리로 넣어준다. 키값을 이용해서 접근하기 때문 days = {1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:30} for tc in range(1,t+1): m1, d1, m2, d2 = map(int,input().split()) result = 0 for i in range(m1,m2): # 달이 같은 경우 if m1 == i: result += days[i] - d1 +1 else: result += days[i] result += d2 print(f'#{tc} {result}') # 딕셔너리의 경우 인덱스 값이 아닌 키를 이용해서 접근하기 때문에 key: value형식으로 놓은 딕..

[SWEA][D2] 1954. 달팽이 숫자 (파이썬/Python)

t = int(input()) for tc in range(1, t+1): n = int(input()) space = [[0]*n for _ in range(n)] #위, 오른쪽, 아래, 왼쪽으로 움직이는 방향전환 dx = [0,1,0,-1] dy = [1,0,-1,0] direction = 0 #초기 좌표 x = y = 0 #space[0][0] = 1 부터 돌면서 진행하기 위함 space[x][y] = 1 for num in range(2, n*n+1): x += dx[direction] y += dy[direction] #2부터 숫자 넣기. space[x][y] = num #범위를 확인해주는 작업 범위를 넘어가지 않으면 계속해서 같은 방향성을 가지고 달팽이가 움직인다. if 0