본문 바로가기

전체 글96

완주하지 못한 선수 ## 🔒 문제. 완주하지 못한 선수def solution(participant, completion): answer = '' temp = set(participant) - set(completion) if len(temp) >= 1: ## if set(참여한 선수) - set(완주한 선수) 원소가 있으면 answer = "".join(list(temp)) ## 해당 원소 출력 else: ## 동일인물이 존재하면 part_dict, comp_dict = {}, {} for i in participant: if i in part_dict: part_dict[i] += 1 else:.. 2024. 8. 19. 18:17
[2022 KAKAO BLIND RECRUITMENT] 주차 요금 계산 ## 🔒 문제. 주차 요금 계산def solution(fees, records): answer = [] import math ## 최종 딕셔너리 형태 ... key=차량번호, value=누적 주차 시간 ## 임시 딕셔너리 형태 ... key=차량번호, value=[in/out 시간] (시간 오름차순 정렬) r_dict_temp = {} r_dict_cum_tm = {} r_dict_fin = {} ## records 문자열 처리 ################# 입력값 예시 ... ["16:00 3961 IN","16:00 0202 IN","18:00 3961 OUT","18:00 0202 OUT","23:58 3961 IN"] for r in ran.. 2024. 8. 14. 11:15
[2018 KAKAO BLIND RECRUITMENT] [3차] 파일명 정렬 ## 🔒 문제. 파일명 정렬import redef solution(files): answer = [] file_dict = {} ## 입력받은 원본 파일명에서 필요한 데이터 분리 및 추출 --> ★ 파일명 정렬 기준 ## head, number, 원본 입력 순서 for txt in files: num = int(re.findall(r"[0-9]+", txt)[0]) hd_tmp = txt[:txt.index(re.findall(r"[0-9]+", txt)[0])] hd = hd_tmp.lower() ord = files.index(txt) file_dict[txt] = [hd, num, ord] ## 정렬 순.. 2024. 8. 13. 09:13
[2021 Dev-Matching: 웹 백엔드 개발자(상반기)] 로또 순위와 최저 순위 ## 🔒 문제. 로또 최고 순위와 최저 순위def solution(lottos, win_nums): answer = [] min_cnt = 0 zero_cnt = 0 for i in lottos: win_idx = 0 if i != 0: for j in win_nums: if i == j and j != 0: min_cnt += 1 win_idx += 1 elif i == 0: zero_cnt += 1 if zero_cnt == 0 and min_cnt == 6: ## 6개 숫자 모두 맞춘 경우 (무조건 .. 2024. 8. 12. 09:56
둘만의 암호 ## 🔒 문제. 둘만의 암호def solution(s, skip, index): answer = '' ## 알파벳 리스트 생성 (아스키 코드) alpha = [chr(i) for i in range(97, 123)] ## 생성한 알파벳 리스트에서 skip할 알파벳 제외 alpha = list(set(alpha) - set(skip)) alpha.sort() ## 변환 (s의 문자열에 index값 만큼 순서를 미룬다) for j in s: idxx_old = alpha.index(j) ## index 추가 전 값 idxx_new = idxx_old + index ## index 추가 후 값 ## 단, 새로운 알파벳 위.. 2024. 8. 11. 16:23
[2020 카카오 인턴십] 키패드 누르기 ## 🔒 문제. [카카오 인턴] 키패드 누르기def solution(numbers, hand): answer = '' keypad = {1:(-1, 3), 2:(0, 3), 3:(1, 3) , 4:(-1, 2), 5:(0, 2), 6:(1, 2) , 7:(-1, 1), 8:(0, 1), 9:(1, 1) , 0:(0, 0)} l_hand_pos = (-1, 0) r_hand_pos = (1, 0) fin_thm = str() for n in numbers: if n in [1, 4, 7]: l_hand_pos = keypad[n] .. 2024. 8. 11. 16:21
10988 ## 10988 팰린드롬word = input()stndrd = len(word)//2if word[0:stndrd] == word[len(word):-stndrd-1:-1]: print(1)else: print(0) 2024. 7. 4. 22:30
두 배열 교집합 ''' 3문제: 두 배열의 교집합두 개의 정수 배열이 주어졌을 때, 두 배열의 교집합을 구하는 함수를 작성하시오. 결과 배열의 각 요소는 중복 없이 나타내야 합니다.조건: 시간 복잡도를 최적화하는 방법을 사용하시오.'''n = set(list(input()))m = set(list(input()))## 교집합 구하기intrsct = n & mprint(list(intrsct))''' 문제점- 입력 처리: input() 함수는 문자열을 읽기 때문에, 입력 값을 정수 배열로 변환해야 합니다. 현재 코드에서는 각 문자를 개별 요소로 취급하고 있어 제대로 된 정수 배열 처리가 이루어지지 않습니다.''' 2024. 7. 1. 23:24
문자열 압축 ''' 2문제 : 문자열 압축주어진 문자열에서 반복되는 문자들을 압축하여 새로운 문자열을 반환하는 함수를 작성하시오. 예를 들어, 입력이 "aaabbcccc"인 경우 "a3b2c4"로 변환하시오.조건: 압축된 문자열의 길이가 원래 문자열보다 길어질 경우 원래 문자열을 반환하시오.'''txt = input()cnt = {}fin = str()## 문자열 하나씩 쪼개서 딕셔너리에 카운트 값 저장for i in txt: if i in cnt: cnt[i] = cnt[i] +1 else: cnt[i] = 1## 딕셔너리 값 합쳐서 출력key = ''.join((list(cnt.keys())))val = ''.join(map(str, list(cnt.values())))for i in range (.. 2024. 7. 1. 22:43