From b8faee93d338bdfc2d98f5dc845966e6c82c0d7c Mon Sep 17 00:00:00 2001 From: Hwang Juhee Date: Wed, 1 Jun 2022 23:04:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20=EB=AA=A8=EC=9D=98=EA=B3=A0?= =?UTF-8?q?=EC=82=AC=20=EC=86=94=EB=A3=A8=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solution.js" | 34 ++++++++++++++ .../\354\243\274\355\235\254/README.md" | 45 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 "problems/\353\252\250\354\235\230\352\263\240\354\202\254/solution.js" create mode 100644 "problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" diff --git "a/problems/\353\252\250\354\235\230\352\263\240\354\202\254/solution.js" "b/problems/\353\252\250\354\235\230\352\263\240\354\202\254/solution.js" new file mode 100644 index 0000000..3d9c262 --- /dev/null +++ "b/problems/\353\252\250\354\235\230\352\263\240\354\202\254/solution.js" @@ -0,0 +1,34 @@ +function solution(answers) { + let answer = []; + + let score = [ 0, 0, 0] + let supo1 = [1,2,3,4,5] + let supo2 = [2,1,2,3,2,4,2,5] + let supo3 = [3,3,1,1,2,2,4,4,5,5] + + + for (var i = 0; i < answers.length; i++){ + if (supo1[i] === answers[i]) score[0]++ + if (supo2[i] === answers[i]) score[1]++ + if (supo3[i] === answers[i]) score[2]++ + + if (i > supo1.length-1) { + if(supo1[i%supo1.length] === answers[i]) score[0]++ + } + if (i > supo2.length-1) { + if(supo2[i%supo2.length] === answers[i]) score[1]++ + } + if (i > supo3.length-1) { + if(supo3[i%supo3.length] === answers[i]) score[2]++ + } + } + + let max_score = Math.max(...score) + let fromIndex = score.indexOf(max_score); + while(fromIndex != -1) { + answer.push(fromIndex+1); + fromIndex = score.indexOf(max_score, fromIndex+1); + } + + return answer; +} \ No newline at end of file diff --git "a/problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" "b/problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" new file mode 100644 index 0000000..8e1cd91 --- /dev/null +++ "b/problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" @@ -0,0 +1,45 @@ +//문제의 수 모름, 정답 모름.. 얘가 맞는지 아닌지 확인하려면 문제 수만큼 각 수포자의 정답을 한번씩 돌아봐야..겠지..? +//1번 수포자는 1,2,3,4,5 순서 +//2번 수포자는 2,1 2,3 2,4 2,5 순서 +//3번 수포자는 3 2번, 1 2번, 2 2번, 4 2번, 5 2번 순서 +//수포자들 정답이 나름 규칙을 가지고 있다면.. 규칙에 맞게 반복해서 정답과 비교해보면 되지 않을까? + +function solution(answers) { //받아오라 문제 정답! + let answer = []; //뱉어내라 누가 젤 많이 맞췄냐! + + let score = [ 0, 0, 0] //각 수포자의 점수를 가지고 있을 배열 + let supo1 = [1,2,3,4,5] //수포자 1번 정답 규칙 아래는 수포자2, 수포자3꺼 + let supo2 = [2,1,2,3,2,4,2,5] + let supo3 = [3,3,1,1,2,2,4,4,5,5] + + + //문제의 수만큼 즉, 정답 배열의 길이만큼 이거를 반복해라잉? + for (var i = 0; i < answers.length; i++){ + if (supo1[i] === answers[i]) score[0]++ + if (supo2[i] === answers[i]) score[1]++ + if (supo3[i] === answers[i]) score[2]++ + // 여기까지 했는데 오류가 남.. 왜지? 왤까? + // 문제 길이가 수포자들이 가지고 있는 정답규칙 배열 길이보다 길면 채점을 못해줬음.. + // 위에와 같은 상황일 때 다시 인덱스를 반복시켜주셈!! + if (i > supo1.length-1) { + if(supo1[i%supo1.length] === answers[i]) score[0]++ + } + if (i > supo2.length-1) { + if(supo2[i%supo2.length] === answers[i]) score[1]++ + } + if (i > supo3.length-1) { + if(supo3[i%supo3.length] === answers[i]) score[2]++ + } + } + + let max_score = Math.max(...score) //전개연산자를 넣어라.. 이유가 뭘까..? + // 특정 값이 있는 모든 위치(index)찾는 반복문! + let fromIndex = score.indexOf(max_score); //가장 높은 점수를 가진 첫번째 인덱스 + while(fromIndex != -1) { + answer.push(fromIndex+1); + fromIndex = score.indexOf(max_score, fromIndex+1); //가장 높은 점수를 가진 값을 찾는데, 앞에서 나온 인덱스보다 뒤에서 찾아! + // 이제 더 이상 가장 높은 점수를 가진 인덱스가 없어! 그럼 -1을 우엑!하고 반복문 마무리. + } + + return answer; +} \ No newline at end of file From b03f91962ca18f5caad97d9b1164459fe667bfe1 Mon Sep 17 00:00:00 2001 From: Hwang Juhee Date: Wed, 1 Jun 2022 23:06:59 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:gear:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=98=EB=A8=B8=EC=8A=A4=20=EB=AC=B8=EC=A0=9C=20=ED=91=9C?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\243\274\355\235\254/README.md" | 2 ++ 1 file changed, 2 insertions(+) diff --git "a/problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" "b/problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" index 8e1cd91..12dc837 100644 --- "a/problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" +++ "b/problems/\353\252\250\354\235\230\352\263\240\354\202\254/\354\243\274\355\235\254/README.md" @@ -1,3 +1,5 @@ +https://programmers.co.kr/learn/courses/30/lessons/42840?language=javascript + //문제의 수 모름, 정답 모름.. 얘가 맞는지 아닌지 확인하려면 문제 수만큼 각 수포자의 정답을 한번씩 돌아봐야..겠지..? //1번 수포자는 1,2,3,4,5 순서 //2번 수포자는 2,1 2,3 2,4 2,5 순서