n, m = map(int, input().split()) visit = [[0] * m for _ in range(n)] # 방문 위치를 저장하기 위한 맵 x, y, d = map(int, input().split()) visit[x][y] = 1 gameMap = [] for i in range(n): gameMap.append(list(map(int, input().split()))) # 북 동 남 서 = 상 우 하 좌 dx = [0, 1, 0, -1] dy = [-1, 0, 1, 0] def turn_left(): global d d -= 1 if d == -1: d = 3 count = 1 # 현재 위치 포함 turn_time = 0 while True: turn_left() nx = x+dx[..
n = input() col = int(ord(n[0])) - 96 row = int(n[1]) result = 0 step = [(2, 1), (2, -1), (-2, 1), (-2, -1), (1, 2), (1, -2), (-1, 2), (-1, -2)] # 이동할 수 있는 가지 수를 저장함 for i in step: n_col = col+i[0] # i의 슬라이스는 x,y, step의 슬라이스는 좌표들 n_row = row+i[1] if n_col >= 1 and n_col = 1 and n_row
구현 머릿속에 있는 알고리즘을 소스코드로 바꾸는 과정 주로, 2차원 공간을 사용함 구현 문제란? 풀이를 떠올리는 것은 쉽지만 소스코드로 옮기기 어려운 문제 알고리즘은 간단한데 코드가 길어지는 문제 소수점, 실수를 다루는 문제 문자열을 끊어 처리하는 문제 적절한 라이브러리를 찾아서 사용해야 하는 문제 예제 4-1. 상하좌우 # 나의 풀이 n = int(input()) mv = input().split() x, y = 1, 1 for i in mv: if x < 1 and y < 1: continue else: if i == 'R': y += 1 print(x, y) elif i == 'L': y -= 1 print(x, y) elif i == 'U': x -= 1 print(x, y) elif i == '..
# 1부터 target-1까지의 숫자를 만들 수 있다. # target보다 작은 지 확인하고 크다면 target값을 업데이트 한다. coin = int(input()) won = sorted(map(int, input().split())) # 3 2 1 1 9 target = 1 # 처음에 1을 만들 수 있는지 확인하기 위해 1로 설정 (1이 최소이므로) for i in won: # 1 1 2 3 9 (5번 돎) if target < i: break target += i # target(= 1)이 1보다 작은지 확인 # target(= 2)이 1보다 작은지 확인 # target(= 3)이 2보다 작은지 확인 # target(= 5)이 3보다 작은지 확인 # target(= 8)이 9보다 작은지 확인 pr..
s = input() count0 = 0 count1 = 0 # 0으로 시작할 때, 1로 시작할 때 두가지 경우를 생각 if s[0] == '0': count0 += 1 elif s[0] == '1': count1 += 1 for i in range(len(s)-1): if s[i] != s[i+1]: # s[0] s[1]이 다르면 아래의 조건문을 실행 if s[i+1] == '1': count1 += 1 elif s[i+1] == '0': count0 += 1 print(min(count0, count1)) # 두 합 중 최솟값을 출력 # count = 0 # list = [] # for i in range(n): # if w[i] in list: # continue # list.append(w[i])..
# 나의 풀이 s = input() result = 1 for i in s: if int(i)