[Programmers] (Javascript) 신고결과 받기
·
💯 CodingTest/Programmers
function solution(id_list, report, k) { let reports = [...new Set(report)].map(a=>{return a.split(' ')}); // Set으로 변환한뒤 해당 원소들을 다시 배열로 가져옴 이때 각 원소에 대해 split을 진행 let count = new Map(); for(const e of reports) { count.set(e[1], count.get(e[1]) + 1 || 1) } let note = new Map(); for (const report of reports) { if (count.get(report[1]) >= k) { note.set(report[0], note.get(report[0])+1 || 1) } } let a..
[Programmers] (Javascript) 다트게임
·
💯 CodingTest/Programmers
function solution(dartResult) { var bonus = new Map([ ['S',1], ['D',2], ['T',3] ]); var option = new Map([ ['*', 2], ['#', -1], ]); var reg = new RegExp(/\d*[SDT][*#]*/,'g'); var list = dartResult.match(reg); var score = new Map(); var index = 0; for (const data of list) { var num = parseInt(data.match(/\d+/g)); var bo = data.match(/[SDT]/g).toString(); //string의 경우 toString을통해 arr => string으로 변..
[Programmers] 다트게임
·
💯 CodingTest/Programmers
▶ 문제 : 더보기 https://programmers.co.kr/learn/courses/30/lessons/17682 ▶ 코드 : def solution(dartResult): numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] divided = [] answer = [] temp = '' for i in range(len(dartResult)): if dartResult[i] in numbers and i == 0: temp += dartResult[i] elif dartResult[i] in numbers and dartResult[i-1] not in numbers: divided.append(temp) temp = dartRe..
[Programmers] 비밀지도
·
💯 CodingTest/Programmers
▶ 문제 : 더보기 https://programmers.co.kr/learn/courses/30/lessons/17681 ▶ 코드 : def solution(n, arr1, arr2): answer = [] for i in range(n): bitStr = bin(arr1[i] | arr2[i]) temp = '' bitStr = bitStr[2:] bitStr = bitStr.rjust(n,'0') #bin() 을 이용하면 맨앞에 0인 부분을 없애버리기에 길이를 맞춰줘야함 => 주의 #bitStr에는 '0b' 가 앞에 포함되어있음 for c in bitStr: if c == '1': temp += '#' elif c == '0': temp += ' ' answer.append(temp) return a..
[Programmers] 실패율
·
💯 CodingTest/Programmers
▶ 문제 : 더보기 https://programmers.co.kr/learn/courses/30/lessons/42889 ▶ 코드 : def solution(N, stages): answer= [] totalUser=len(stages) count = {} for i in range(N): count[i+1] = 0 stages.sort() for stage in stages: if stage == N+1: continue else: count[stage] += 1 failure = {} for i in range(1,N+1): if totalUser == 0: failure[i] = 0 else: failure[i] = count[i]/totalUser totalUser -= count[i] answe..
[Programmers] 크레인 인형뽑기 게임
·
💯 CodingTest/Programmers
▶ 문제 : 더보기 https://programmers.co.kr/learn/courses/30/lessons/64061 ▶ 코드 : from collections import deque def solution(board, moves): count = 0 st = deque() for num in moves: for i in range(len(board)): item = board[i][num-1] if item == 0: continue else: if len(st) != 0: recent_item = st.popleft() if recent_item == item: count += 2 else: st.appendleft(recent_item) st.appendleft(item) else: st.app..
[Programmers] 키패드 누르기
·
💯 CodingTest/Programmers
▶ 문제 : 더보기 https://programmers.co.kr/learn/courses/30/lessons/67256 ▶ 코드 : keyPad = { '1' : (0,0), '2' : (0,1), '3' : (0,2), '4' : (1,0), '5' : (1,1), '6' : (1,2), '7' : (2,0), '8' : (2,1), '9' : (2,2), '*' : (3,0), '0' : (3,1), '#' : (3,2) } def solution(numbers, hand): answer='' left = '*' right = '#' for num in numbers: if num in [1, 4, 7] : answer += 'L' left = str(num) elif num in [3, 6, 9]..