프로그래머스 LV1(4)
2024. 1. 26. 16:40ㆍ백준 및 프로그래머스/프로그래머스 LV 1
-푸드 파이터 대회
def solution(food):
answer = ''
fod = []
for i in range(len(food)):
if food[i] // 2 == 0:
pass
elif food[i] % 2 == 1:
for j in range(food[i]//2):
fod.append(i)
elif food[i] % 2==0:
for _ in range(food[i]//2):
fod.append(i)
fod.append(0)
fod+=fod[-2::-1]
return ''.join(map(str,fod))
-k번째수
def solution(array, commands):
answer = []
for i in range(len(commands)):
tal = array[commands[i][0] - 1 : commands[i][1]]
tal.sort()
answer.append(tal[commands[i][2] - 1])
return answer
-문자열 내 마음대로 정렬하기
def solution(strings, n):
answer = []
strings.sort()
strings.sort(key = lambda x:x[n])
return strings
-두개 뽑아서 더하기
def solution(numbers):
answer = []
for i in range(len(numbers)):
for j in range(i+1,len(numbers)):
answer.append(numbers[i]+numbers[j])
answer =list(set(answer))
answer.sort()
return answer
-1차 비밀지도
def solution(n, arr1, arr2):
maps = []
maps2= []
for i in range(n):
tal = list(str(bin(arr1[i])[2:]))
tal2 = list(str(bin(arr2[i])[2:]))
if len(tal) < n:
for i in range(n - len(tal)):
tal.insert(0,"0")
if len(tal2) < n:
for i in range(n - len(tal2)):
tal2.insert(0,"0")
maps.append("".join(tal))
maps2.append("".join(tal2))
password = ""
secret_maps = []
for i,j in zip(maps,maps2):
for x,y in zip(i,j):
if x == "0" and y == "0":
password+=" "
else:
password+="#"
secret_maps.append(password)
password=""
return secret_maps'백준 및 프로그래머스 > 프로그래머스 LV 1' 카테고리의 다른 글
| 프로그래머스 LV 1 (0) | 2024.01.28 |
|---|---|
| 프로그래머스 LV 1(5) (0) | 2024.01.26 |
| 프로그래머스 LV1(3) (2) | 2024.01.26 |
| 프로그래머스 LV 1(2) (0) | 2024.01.25 |
| 프로그래머스 1LV (1) (0) | 2024.01.25 |