From 11b079b0069c55cbd9fd055ee85c0f0fb69b4456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=EB=8C=80=ED=98=84?= Date: Mon, 28 Oct 2024 06:35:37 +0900 Subject: [PATCH] =?UTF-8?q?2=EC=A3=BC=EC=B0=A8=20=EA=B3=BC=EC=A0=9C?= =?UTF-8?q?=EC=9E=85=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/problem1.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- src/problem2.js | 19 ++++++++++++++++++ src/problem3.js | 18 +++++++++++++++-- src/problem4.js | 19 ++++++++++++++++-- src/problem5.js | 21 ++++++++++++++++++-- src/problem6.js | 32 +++++++++++++++++++++++++++++-- src/problem7.js | 36 ++++++++++++++++++++++++++++++++-- 7 files changed, 185 insertions(+), 11 deletions(-) diff --git a/src/problem1.js b/src/problem1.js index 9a14f2c..726a5c1 100644 --- a/src/problem1.js +++ b/src/problem1.js @@ -1,5 +1,54 @@ function problem1(pobi, crong) { - var answer; + if(pobi[0]+1 === pobi[1] && crong[0]+1 === crong[1]){ + var pobi_num; + var crong_num; + var multiple_num=1; + var addition_num=0; + var answer; + + function get_num(arr){ + for(var i=0; i<2; i++){ + var maxvalue; + + n = arr[i].toString(); + for(let j of n){ + addition_num += Number(j); + multiple_num *= Number(j); + } + if (addition_num > multiple_num){ + arr[i] = addition_num; + } + else{ + arr[i] = multiple_num; + } + addition_num = 0; + multiple_num = 1; + } + if(arr[0] > arr[1]){ + maxvalue = arr[0]; + } + else + maxvalue = arr[1]; + return maxvalue; + } + + pobi_num = get_num(pobi); + crong_num = get_num(crong); + + if(pobi_num > crong_num){ + answer = 1; + } + else if(pobi_num < crong_num){ + answer = 2; + } + else if(pobi_num == crong_num){ + answer = 0; + } + else{ + answer = -1; + } + } else answer = -1; + return answer; } diff --git a/src/problem2.js b/src/problem2.js index cebd07c..355b0a4 100644 --- a/src/problem2.js +++ b/src/problem2.js @@ -1,5 +1,24 @@ function problem2(cryptogram) { var answer; + var stack = []; + var length = 0; + + n = cryptogram; + for(let j = 0; j < n.length; j++){ + stack.push(n[j]); + } + while(length != stack.length){ + length = stack.length; + + for(var i=0; i= 65 && askii <= 90){ + word_list_rev.push(String.fromCharCode(155-askii)); + } + else if(askii >= 97 && askii <= 122){ + word_list_rev.push(String.fromCharCode(219-askii)); + } + else{ + word_list_rev.push(' '); + } + } + return word_list_rev.join(''); } module.exports = problem4; diff --git a/src/problem5.js b/src/problem5.js index 9368e87..3f7af66 100644 --- a/src/problem5.js +++ b/src/problem5.js @@ -1,6 +1,23 @@ function problem5(money) { - var answer; - return answer; + var goodthing = [0,0,0,0,0,0,0,0,0]; + goodthing[0] = Math.floor(money/50000); + money %= 50000; + goodthing[1] = Math.floor(money/10000); + money %= 10000; + goodthing[2] = Math.floor(money/5000); + money %= 5000; + goodthing[3] = Math.floor(money/1000); + money %= 1000; + goodthing[4] = Math.floor(money/500); + money %= 500; + goodthing[5] = Math.floor(money/100); + money %= 100; + goodthing[6] = Math.floor(money/50); + money %= 50; + goodthing[7] = Math.floor(money/10); + money %= 10; + goodthing[8] = Math.floor(money/1); + return goodthing; } module.exports = problem5; diff --git a/src/problem6.js b/src/problem6.js index 3f842b5..47674e8 100644 --- a/src/problem6.js +++ b/src/problem6.js @@ -1,6 +1,34 @@ function problem6(forms) { - var answer; - return answer; + const emailSet = new Set(); + + function getchars(nickname) { + const name = new Set(); + for (let i = 0; i < nickname.length - 1; i++) { + name.add(nickname.slice(i, i + 2)); + } + return Array.from(name); + } + + for (let i = 0; i < forms.length; i++) { + const [email1, nickname1] = forms[i]; + const name1Substrings = getchars(nickname1); + + for (let j = 0; j < forms.length; j++) { + if (i === j) continue; + + const [email2, nickname2] = forms[j]; + for (const substring of name1Substrings) { + const regExp = new RegExp(substring); + if (regExp.test(nickname2)) { + emailSet.add(email1); + emailSet.add(email2); + break; + } + } + } + } + + return Array.from(emailSet).sort(); } module.exports = problem6; diff --git a/src/problem7.js b/src/problem7.js index ee1bb9d..2b7d7e1 100644 --- a/src/problem7.js +++ b/src/problem7.js @@ -1,6 +1,38 @@ function problem7(user, friends, visitors) { - var answer; - return answer; + const clsrn = new Set(); + var score = new Map(); + var result = []; + + friends.forEach(element => {//친구들 셋 추가 + const[friend1,friend2]= element; + if(user === friend1){ + clsrn.add(friend2); + } + if(user === friend2){ + clsrn.add(friend1); + } + }); + + + friends.forEach(element => {//친구의 친구 10점 추가 + const [friend1,friend2] = element; + if(clsrn.has(friend1) && friend2!==user && !clsrn.has(friend2)){ + score.set(friend2,(score.get(friend2)||0)+10); + } + + if(clsrn.has(friend2) && friend1 !== user &&clsrn.has(friend1)){ + score.set(friend1,(score.get(friend1)||0)+10); + } + }); + + visitors.forEach(visitor => {//방문자 1점 추가 + if(!clsrn.has(visitor)){ + score.set(visitor,(score.get(visitor)||0)+1); + } + }); + + result=Array.from(score).sort((a, b) => b[1] - a[1]).map(item => item[0]); + return result; } module.exports = problem7;