목록Coding test(Python3)/Programmers (115)
NIRVANA
1. 문제 코니는 매일 다른 옷을 조합하여 입는것을 좋아합니다.예를 들어 코니가 가진 옷이 아래와 같고, 오늘 코니가 동그란 안경, 긴 코트, 파란색 티셔츠를 입었다면 다음날은 청바지를 추가로 입거나 동그란 안경 대신 검정 선글라스를 착용하거나 해야합니다.코니는 각 종류별로 최대 1가지 의상만 착용할 수 있습니다. 예를 들어 위 예시의 경우 동그란 안경과 검정 선글라스를 동시에 착용할 수는 없습니다.착용한 의상의 일부가 겹치더라도, 다른 의상이 겹치지 않거나, 혹은 의상을 추가로 더 착용한 경우에는 서로 다른 방법으로 옷을 착용한 것으로 계산합니다.코니는 하루에 최소 한 개의 의상은 입습니다.코니가 가진 의상들이 담긴 2차원 배열 clothes가 주어질 때 서로 다른 옷의 조합의 수를 return 하도..
1. 문제전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다.전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다.구조대 : 119박준영 : 97 674 223지영석 : 11 9552 4421전화번호부에 적힌 전화번호를 담은 배열 phone_book 이 solution 함수의 매개변수로 주어질 때, 어떤 번호가 다른 번호의 접두어인 경우가 있으면 false를 그렇지 않으면 true를 return 하도록 solution 함수를 작성해주세요.제한 사항phone_book의 길이는 1 이상 1,000,000 이하입니다.각 전화번호의 길이는 1 이상 20 이하입니다.같은 전화번호가 중복해서 들어있지 않습니다. 2. 문제 풀이 문제 풀이 접근법..
1. 문제정수 n이 매개변수로 주어질 때 n의 각 자리 숫자의 합을 return하도록 solution 함수를 완성해주세요 2. 문제 풀이 방법def solution(n): num = list(map(int, list(str(n)))) answer = sum(num) return answer 다른 문제 풀이 방법1) 숫자를 10으로 나눈 나머지를 answer에 더한다.2) n을 10으로 나눈 몫을 n으로 업데이트 한다. 3) n이 0이 될 때 까지 해당 과정을 반복한다.def solution(n): answer = 0 while n: answer += n % 10 n //= 10 return answer 해당 과정을 divm..
1. 문제my_string은 "3 + 5"처럼 문자열로 된 수식입니다. 문자열 my_string이 매개변수로 주어질 때, 수식을 계산한 값을 return 하는 solution 함수를 완성해주세요. 제한사항연산자는 +, -만 존재합니다.문자열의 시작과 끝에는 공백이 없습니다.0으로 시작하는 숫자는 주어지지 않습니다.잘못된 수식은 주어지지 않습니다.5 ≤ my_string의 길이 ≤ 100my_string을 계산한 결과값은 1 이상 100,000 이하입니다.my_string의 중간 계산 값은 -100,000 이상 100,000 이하입니다.계산에 사용하는 숫자는 1 이상 20,000 이하인 자연수입니다.my_string에는 연산자가 적어도 하나 포함되어 있습니다.return type 은 정수형입니다.my_st..
문제 경화는 과수원에서 귤을 수확했습니다. 경화는 수확한 귤 중 'k'개를 골라 상자 하나에 담아 판매하려고 합니다. 그런데 수확한 귤의 크기가 일정하지 않아 보기에 좋지 않다고 생각한 경화는 귤을 크기별로 분류했을 때 서로 다른 종류의 수를 최소화하고 싶습니다. 예를 들어, 경화가 수확한 귤 8개의 크기가 [1, 3, 2, 5, 4, 5, 2, 3] 이라고 합시다. 경화가 귤 6개를 판매하고 싶다면, 크기가 1, 4인 귤을 제외한 여섯 개의 귤을 상자에 담으면, 귤의 크기의 종류가 2, 3, 5로 총 3가지가 되며 이때가 서로 다른 종류가 최소일 때입니다. 경화가 한 상자에 담으려는 귤의 개수 k와 귤의 크기를 담은 배열 tangerine이 매개변수로 주어집니다. 경화가 귤 k개를 고를 때 크기가 서로..
문제 효진이는 멀리 뛰기를 연습하고 있습니다. 효진이는 한번에 1칸, 또는 2칸을 뛸 수 있습니다. 칸이 총 4개 있을 때, 효진이는 (1칸, 1칸, 1칸, 1칸) (1칸, 2칸, 1칸) (1칸, 1칸, 2칸) (2칸, 1칸, 1칸) (2칸, 2칸) 의 5가지 방법으로 맨 끝 칸에 도달할 수 있습니다. 멀리뛰기에 사용될 칸의 수 n이 주어질 때, 효진이가 끝에 도달하는 방법이 몇 가지인지 알아내, 여기에 1234567를 나눈 나머지를 리턴하는 함수, solution을 완성하세요. 예를 들어 4가 입력된다면, 5를 return하면 됩니다. n에 따라 나올 수 있는 경우의 수를 생각해보면 다음과 같다. n 경우의 수 1 1 2 2 3 3 4 5 5 8 확인해보면 1과 2 이후부터는 F(n) = F(n-1) ..