๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ํ”„์—” ๊ณต๋ถ€

(151)
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] ์˜์–ด๊ฐ€ ์‹ซ์–ด์š” || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ function solution(numbers) { var answer = 0; const en = { "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9 }; const keys = Object.keys(en); for (let i = 0; i < keys.length; i++) { numbers = numbers.replaceAll(keys[i], en[`${keys[i]}`]); } return Number(numbers); } key๋“ค์„ ๋ฐฐ์—ด๋กœ ๋งŒ๋“  ํ›„, ๊ทธ ๋ฐฐ์—ด์˜ ๊ฐ’๋“ค์„ ํ•˜๋‚˜์”ฉ value๋กœ ๋ฐ”๊ฟ”์คฌ๋‹ค. ๋ณ€๊ฒฝํ•˜๋Š” ๋ถ€๋ถ„์„ ์ด๋ ‡๊ฒŒ, replace ์— ๋‘๋ฒˆ์งธ ์ธ์ž..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] ์ด์ง„์ˆ˜ ๋”ํ•˜๊ธฐ || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ function solution(bin1, bin2) { return (parseInt(bin1, 2) + parseInt(bin2, 2)).toString(2); } parseInt ๋กœ ํŠน์ • ์ธ์ˆ˜๋กœ ์ธ์‹ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑธ ์ฒ˜์Œ ์•Œ์•˜๋‹ค. ๊ทธ๋ฆฌ๊ณ  toString ์œผ๋กœ ํŠน์ • ์ธ์ˆ˜๋กœ ๋ณ€ํ™˜ ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ๋„ ์ฒ˜์Œ ์•Œ์•˜์Œ! https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/parseInt parseInt() - JavaScript | MDN parseInt() ํ•จ์ˆ˜๋Š” ๋ฌธ์ž์—ด ์ธ์ž๋ฅผ ํŒŒ์‹ฑํ•˜์—ฌ ํŠน์ • ์ง„์ˆ˜(์ˆ˜์˜ ์ง„๋ฒ• ์ฒด๊ณ„์—์„œ ๊ธฐ์ค€์ด ๋˜๋Š” ๊ฐ’)์˜ ์ •์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. developer.mozilla.org
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/Javascript] ํ•œ ๋ฒˆ๋งŒ ๋“ฑ์žฅํ•œ ๋ฌธ์ž || ์ฝ”๋”ฉํ…Œ์ŠคํŠธ function solution(s) { const set = new Set(s.split("")); let result = []; Array(...set).map(v => { let reg = new RegExp(`[${v}]`, 'g'); s.match(reg).length === 1 && result.push(v); }) return result.sort().join(""); } set์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ์ค‘๋ณต๋˜์ง€ ์•Š์€ ์•ŒํŒŒ๋ฒณ์„ ํ•˜๋‚˜์”ฉ reg ๋ฌธ์œผ๋กœ match ํ•œ ํ›„, ๊ธธ์ด๊ฐ€ 1์ด๋ฉด ๊ฒฐ๊ณผ ๋ฐฐ์—ด์— ๋„ฃ์–ด์คฌ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฒฐ๊ณผ ๋ฐฐ์—ด์„ ์•ŒํŒŒ๋ฒณ์ˆœ์œผ๋กœ sort ํ•ด์ค€ ํ›„ ๋ฌธ์ž์—ด๋กœ return ํ•ด์คŒ. โšก์ •๊ทœ์‹์— ๋ณ€์ˆ˜ ๋„ฃ๋Š” ๋ฒ• const ๋ณ€์ˆ˜ = 'abc'; const regex = new RegExp(`[${๋ณ€์ˆ˜}]`, '..
[๋ฐฑ์ค€/Node.js] 2941๋ฒˆ. ํฌ๋กœ์•„ํ‹ฐ์•„ ์•ŒํŒŒ๋ฒณ || ํ’€์ด JavaScript ์–ด์ œ ์œ ํˆฝ์—์„œ ์ดˆ๋ณด์ž๋“ค์ด ํ•˜๊ธฐ ์‰ฌ์šด ๋‚˜์œ ์ฝ”๋”ฉ ์Šต๊ด€์„ ๋ดค๋‹ค. ๊ทธ๋Ÿฐ ์˜์ƒ๋“ค์„ ํ•œ๋ฒˆ์”ฉ ๋ณด๋ฉด ํ™•์‹คํžˆ ๋‹ค์Œ๋‚  ์ฝ”๋”ฉํ•  ๋•Œ ์กฐ๊ธˆ์”ฉ ๋” ์ƒ๊ฐํ•˜๊ณ , ๋‚˜์€ ์ฝ”๋“œ๋ฅผ ์งค ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ๋ฌดํŠผ, ์ž˜ ๋‚˜์˜ค๋Š”๋ฐ ํ‹€๋ ธ๋‹ค๊ณ  ๋‚˜์™”๋‹ค. let input = require('fs').readFileSync('/dev/stdin').toString(); const cro = ['c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z='] for (let i = 0; i < cro.length; i++) { input = input.replaceAll(cro[i], "C"); } console.log(Number(input.length)); ์ฒ˜์Œ์—” split์œผ๋กœ ๋‚˜๋ˆŒ๊นŒ ํ•˜๋‹ค๊ฐ€ ๊ทธ๋Ÿผ array๊ฐ€ ๋˜๋‹ˆ๊นŒ ๊ดœํžˆ ๊ณผ์ •์ด..
[๋ฐฑ์ค€/Node.js] 1157๋ฒˆ. ๋ฐ”๊ตฌ๋‹ˆ ์ˆœ์„œ ๋ฐ”๊พธ๊ธฐ || ํ’€์ด JavaScript const input = require('fs').readFileSync('/dev/stdin').toString().split("\n").map(v => (v.replace("\r", ""))); const arr = input.map(v => v.split(" ")); const N = arr[0][0]; const M = arr[0][1]; let baskets = []; let baskets2 = []; for (let i = 1; i { let rotateNum = []; rotateNum = baskets.splice(start - 1, end - start + 1); const originMidIndex = baskets2[mid - 1]; const newMidIndex = rotateNu..
[๋ฐฑ์ค€/Node.js] 4344๋ฒˆ ํ‰๊ท ์€ ๋„˜๊ฒ ์ง€ || ํ’€์ด JavaScript let input = require('fs').readFileSync('/dev/stdin').toString().split('\n'); const test = +input[0]; for (let i = 1; i Number(v)); let student = sub.shift(); let ever = sub.reduce((sum, v) => sum + v, 0) / student; let overEver = sub.filter(v => v > ever); let percent = ((overEver.length / student )* 100).toFixed(3); console.log(percent + '%'); } test ํ…Œ์ŠคํŠธ ์ˆ˜๋ฅผ ๋ฐ›์•„์™€์„œ for ๋ฌธ์œผ๋กœ ๊ฐ’์„ ๋„์ถœํ•œ๋‹ค. ๊ณผ๋ชฉ๊ณผ ํ•™์ƒ ์ˆ˜๊ฐ€ ํฌํ•จ๋œ ๋ฐฐ..
[๋ฐฑ์ค€/Node.js] 1157๋ฒˆ ๋‹จ์–ด ๊ณต๋ถ€ || ํ’€์ด JavaScript const input = require('fs').readFileSync('/dev/stdin').toString().trim().replaceAll("\r" && "\n", "").toUpperCase().split(""); let countArr = []; const inputSet = new Set(input); const onlyItem = [...inputSet]; onlyItem.map(v => { let count = 0; for (let i = 0; i < input.length; i++) { v === input[i] && count++; } countArr.push({ [v]: count }); }) let num = []; for (let i = 0; i < countArr.lengt..
[๋ฐฑ์ค€/Node.js] 10757๋ฒˆ ํฐ์ˆ˜ A + B || ํ’€์ด JavaScript const input = require('fs').readFileSync('/dev/stdin').toString().split(" ").map(v => BigInt(v)); console.log((input[0] + input[1]).toString()); ์ฒ˜์Œ์— ๊ทธ๋ƒฅ ๋”ํ•œ ์ˆซ์ž์—์„œ 100์˜ ์ž๋ฆฌ ์ดํ•˜๋Š” ๋‚ด๋ฆผ ์ฒ˜๋ฆฌ ๋˜๊ธธ๋ž˜ ์—ฅ ์ด๊ฑฐ BigInt ์ธ๊ฐ€? ์‹ถ์–ด์„œ ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ˆ, ๋งž์•˜๋‹ค. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/BigInt BigInt - JavaScript | MDN BigInt ๋Š” Number ์›์‹œ ๊ฐ’์ด ์•ˆ์ •์ ์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€์น˜์ธ 2^53 - 1๋ณด๋‹ค ํฐ ์ •์ˆ˜๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๋‚ด์žฅ ๊ฐ์ฒด..

728x90
๋ฐ˜์‘ํ˜•