알고리즘
-
[프로그래머스 1단계] [1차] 다트 게임알고리즘 2024. 2. 13. 18:09
❓문제 설명 다트게임을 할것임 3번을 던져서 보너스도 있고 감점하게 만드는 요소도 있음 게다가 다트가 박히는 구역별로 제곱값 또는 세제곱값을 주는 요소도 있음 그래서 대충 "1D2S#10S" 이런식으로 문자열이 나오는데 이걸 점수로 바꿔놓아야함 부가적은 조건은 문제에 보면 있음 그거 보면서 풀어보셈 ✅ 문제 해결 예외에 대한 처리를 해야하는데 어디서부터 해야할지 막막했음. *이게 연산을 개떡같이 하니깐 이거부터 처리할까하다가 반복문을 돌리게 되면 문자 하나씩 들어갈텐데 10이라는 숫자가 눈에 띄었음 그래서 이거 먼저 처리하고 나머지 값에 대해서 처리를 해야할 것 같음 이후에는 반복문을 돌았을 때 어떠한 값을 return해주면 되는데 이럴 때에는 break를 쓰는게 좋을 것 같아 switch를 사용해보겠음..
-
[프로그래머스 1단계] [1차] 비밀지도알고리즘 2024. 2. 5. 18:29
❓문제 설명 한 변의 길이가 n인 정사각형이 있음 변의 길이만큼 블록이 나올 것임 ex)4 x 4 각 블록을 겹처서 최종적으로 하나의 블록을 만들어야 함 블록이 한군데라도 칠해져있다면 칠한채로 둘다 칠해지지 않았다면 안칠한채로 합칠 것임 주어지는 값은 변의 길이인 n, 배열 2개 (2진법으로 바꿔야하는 것임) 출력값으로 비밀지로를 만들어야 함 ex) ["#####","# # #", "### #", "# ##", "#####"] ✅ 문제 해결 배열 두개를 index값을 통해 가져와서 합칠 것임 그리고 그 합친 값에 대해서 0 = " ", 1 = "#"으로 바꿀 것임 이진법으로 나타내는 방법을 알아야 함 문자열.toString(2) 원하는 길이만큼 만들어야하는데 둘 다 앞이 0일때는 길이가 점점 줄어든다 그..
-
[프로그래머스 1단계] 신고 결과 받기알고리즘 2024. 1. 29. 18:54
❓문제 설명 신고한 array와 신고 내용에 대한 array가 있고 limit을 나타내는 k가 있다 이러쿵 저러쿵해서 A를 신고한 B는 A가 k이상의 신고를 받게 되면 A가 정지가 되었다는 알림을 받는 것임 최종적으로 사용자들이 몇번이나 알림을 받는지 array를 반환하는 것임 테스트 코드는 통과하였지만 제출할 때 정답률 60%로 나오는데 왜 이러는걸까? - 느낀점 1 ✅ 문제 해결 배열을 value로 가지고 key는 reportedUser인 객체 하나를 만들어서 배열에 신고한 reportUser를 넣을 것임 결국 신고를 받은 유저의 배열의 길이가 2이상이면 그 배열 안을 돌면서 값을 올려주면 되는 것임 function solution(id_list, report, k) { const answer = n..
-
[프로그래머스 1단계] 성격 유형 검사하기알고리즘 2024. 1. 26. 16:18
❓문제 설명 length가 2인 문자열로 이루어진 배열을 줄 것임 숫자로 이루어진 동일한 length의 배열도 하나 줄 것임 두개를 짬뽕해서 어쩌구저쩌구 해서 문자 하나만 뽑으셈 사실 MBTI였음 이때까지 나온거 합쳐서 length가 4인 문자열 하나 출력해보셈 function solution(survey, choices) { const types = {} const answer = [] "RTCFJMAN".split("").map(item => types[item] = 0) const newChoices = choices.map(item => item - 4) for (item of survey) { const [left, right] = item.split("") const index = survey..