코딩테스트/이코테 2021

코딩테스트/이코테 2021

[이코테2021] 정렬된 배열에서 특정 수의 개수 구하기 [이진탐색] - Python

from bisect import bisect_left, bisect_right def numCnt(): # 배열에 찾고자 하는 값이 없다면 None 리턴 if x not in array: return None left_index = bisect_left(array, x) right_index = bisect_right(array, x) return right_index-left_index n, x = map(int, input().split()) array = list(map(int, input().split())) result = numCnt() if result == None: print(-1) else: print(result)

코딩테스트/이코테 2021

[이코테2021] 절단기로 떡 자르기 [이진탐색] - Python

# 떡의 개수(n)와 요청한 떡의 길이(m)를 입력 n, m = map(int, input().split()) # 각 떡의 개별 높이 정보를 입력 array = list(map(int, input().split())) # 이진 탐색을 위한 시작점과 끝점 설정 start = 0 end = max(array) # 이진 탐색 수행 result = 0 while(start mid: total += x-mid # total이 m보다 작다면 적어도 m만큼은 되어야하니까 절단기 높이(mid) 낮추기 if total < m: end = mid-1 # total이 m보다 크다면 절단기 높이(mid) 높이고 result에 total 삽입 else: result = mid start = mid+1 print(result)

코딩테스트/이코테 2021

[이코테2021] 왕실의 나이트 - Python

loc = input() #값 입력 locX = ['a','b','c','d','e','f','g','h'] #x좌표 인덱스 locY = ['1','2','3','4','5','6','7','8'] #y좌표 인덱 cnt = 0 # 이동 가능한 경우의 수 #상단 오른쪽부터 시계방향으로 이동 범위 dx = [1,2,2,1,-1,-2,-2,-1] dy = [-2,-1,1,2,2,1,-1,-2] x = locX.index(loc[0])+1 #x좌표값 구하기 y = locY.index(loc[1])+1 #y좌표값 구하기 #이동한 x,y의 위치가 1이상이면 카운트 for i in range(len(dx)): if x+dx[i] > 0 and y+dy[i]>0: cnt+=1 print(cnt)

코딩테스트/이코테 2021

[이코테2021] 시각 - Python

# 정수 N이 입력되면 00시 00분 00초부터 N시 59분 59초까지 모든 시각중에서 # 3이 하나라도 포함되는 모든 경우의 수를 구하는 프로그램을 작성하세 n = int(input()) find = 3 #찾는 수 cnt = 0 # 시간에 FIND가 있는 경우의 수 min_cnt = 0 #00분00초~59분59초 사이에 FIND가 있는 경우의 수 #시간에 FIND가 포함되지 않은 경우, #00분00초~59분59초 사이에 FIND가 있는 경우의 수를 더해줌 for i in range(60): for k in range(60): if str(find) in str(i)+str(k): min_cnt+=1 for hour in range(n+1): if str(find) in str(hour): cnt += ..

코딩테스트/이코테 2021

[이코테2021] 상하좌우 - Python

n = int(input()) direct = list(map(str,input().split())) x = 1 y = 1 #방 direction = ['U','D','L','R'] #상 하 좌 우 dx = [0,0,-1,1] dy = [-1,1,0,0] for d in direct: v = direction.index(d) if (x + dx[v]) < 1 or (y + dy[v]) < 1: continue else: x += dx[v] y += dy[v] print('x={}, y={}'.format(y,x))

코딩테스트/이코테 2021

[이코테2021] 문자열 재정렬 - Python

data = input() num = ['1','2','3','4','5','6','7','8','9'] num_list = list() alpha_list = list() for d in data: if d in num: num_list.append(int(d)) else: alpha_list.append(d) alpha_list.sort() alpha_list.append(str(sum(num_list))) for a in alpha_list: print(a,end='')

코딩테스트/이코테 2021

[이코테2021] 모험가 길드 - Python

import sys input=sys.stdin.readline n = int(input()) data = list(map(int,input().split())) data.sort() result = 0 # 총 그룹의 수 count = 0 #현재 그룹에 포함된 모험가의 수 for i in data: count += 1 if count >= i: result += 1 count = 0 print(result)

코딩테스트/이코테 2021

[이코테2021] 곱하기 혹은 더하기 - Python

import sys input=sys.stdin.readline n = input() result = int(n[0]) for i in range(1,len(n)-1): num = int(n[i]) if num

PgmJUN
'코딩테스트/이코테 2021' 카테고리의 글 목록