memostack
article thumbnail
백준 11720번 / 숫자의 합 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 19. 21:33

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 입력값을 각 문자로 나눠서 배열로 만든 뒤에 reduce()로 누적값을 구한다. 문자열 정수 값을 +연산자로 숫자 형태로 변환하여 합을 구한다. const solution = (input) => input[1].split('').reduce((acc, n) => +n + acc, 0); const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line', (line) => input.push(line)) .on('close', (_) => { console.log(solution(input)); process.e..

article thumbnail
Chrome 웹 브라우저 내부 아키텍처 및 동작 살펴보기 (1부)
Frontend 2022. 8. 18. 21:23

1부에서는 핵심 컴퓨팅 용어와 Chrome의 다중 프로세스 아키텍처에 대해 살펴봅니다. CPU & GPU 브라우저가 실행되는 환경을 이해하려면 컴퓨터 부품과 역할에 대해 이해하여야 합니다. CPU CPU(Central Processing Unit)는 "중앙 처리 장치"라고 불리며, 컴퓨터의 두뇌 역할을 합니다. CPU에는 CPU core가 있어, 많고 다양한 작업을 하나씩 처리합니다. 과거에는 대부분 CPU가 단일 칩이었습니다. 최신 하드웨어에서는 종종 두 개 이상의 CPU core를 사용하여 휴대폰, 데스크탑 등 과거에 비해 더 좋은 컴퓨팅(Computing) 성능을 제공합니다. GPU GPU(Graphics Processing Unit)는 "그래픽 처리 장치"라고 불립니다. CPU와 달리 GPU는 동..

article thumbnail
백준 10809번 / 알파벳 찾기 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 17. 21:24

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 풀이 const solution = (input) => { const en = [...Array(26).keys()].map((_) => -1); input.split('').forEach((c, idx) => { const cIdx = c.charCodeAt(0) - 97; if (en[cIdx] === -1) { en[cIdx] = idx; } }); return en.join(' '); }; const print = (input) => console.log(solution(input + '')); process.stdin.on('data', print); 상세 설명 알파벳 개수 길이(a~z, 26..

article thumbnail
백준 1065번 / 한수 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 16. 21:48

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 const isHanNum = (n) => { if (n 0) { const curNum = t % 10; if (prevNum != null) { const curDelta = prevNum - curNum; if (delta != null && curDelta !== delta) { return false; } delta = curDelta; } prevNum = curNum; t = parseInt(t / 10); } return true; }; const solution = ..

article thumbnail
백준 4673번 / 셀프 넘버 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 15. 21:06

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 const d = (n) => { const answer = [n]; let t = n; while (t > 0) { answer.push(t % 10); t = parseInt(t / 10); } return answer.reduce((acc, n) => acc + n, 0); }; const solution = () => { const checkSelfNum = [...Array(10001).keys()].map((_) => true); [...Array(10000).keys()].forEach((i) => (checkSelfNum[d(i + 1)] = false)); return checkSelfNum..

article thumbnail
백준 4344번 / 평균은 넘겠지 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 14. 13:17

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 반 평균을 먼저 구한뒤에 각 학생의 점수를 하나씩 비교하여, 평균보다 크면 카운트를 증가시켜주도록 했다. const solution = (input) => { return [...Array(+input[0]).keys()] .map((idx) => { const list = input[idx + 1].split(' ').map((c) => +c); const studentCount = list[0]; const scores = list.slice(1, list.length); const avg = scores.reduce((acc, n) => acc + n, 0) / studentCount; return `..

article thumbnail
백준 8958번 / OX퀴즈 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 13. 16:49

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 한 글자씩 iteration을 하면서, X를 만나면 증가시켜줄 점수(score)를 0으로 초기화해준다. O를 만나면 점수(score) 값을 1씩 증가시켜주면서, 계속해서 총 합을 구하면 된다. const solution = (input) => { const n = +input[0]; return [...Array(n).keys()] .map((i) => { return input[i + 1].split('').reduce( (acc, c) => { if (c === 'X') { acc.score = 0; } else { acc.score += 1; acc.rs += acc.score; } return acc..

article thumbnail
백준 1546번 / 평균 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 12. 21:27

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 입력 받은 값을 조작하여 새로운 값을 만든 뒤, 평균을 구하는 간단한 문제이다. 오차 10^-2까지 허용하기 때문에 반올림과 같은 작업을 해줄 필요없다. const solution = (input) => { const nums = input[1].split(' ').map((s) => +s); const max = Math.max(...nums); return nums.reduce((acc, n) => acc + (n / max) * 100, 0) / nums.length; }; const input = []; require('readline') .createInterface({ input: process...

article thumbnail
백준 3052번 / 나머지 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 11. 21:19

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 중복 제거를 위해 집합의 성질을 활용하면 쉽게 풀 수 있다. const solution = (input) => new Set(input.map((s) => +s % 42)).size; const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line', (line) => input.push(line)) .on('close', (_) => { console.log(solution(input)); process.exit(0); }); 전체 코드 https://github.com/bluemiv/Algorithm/blo..

article thumbnail
백준 2577번 / 숫자의 개수 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 10. 21:10

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 입력받은 숫자의 곱을 구하고, 각 숫자가 몇개씩 들어갔는지 출력하는 문제이다. 대부분 곱을 구한뒤에 문자열로 치환해서 이터레이션 돌면서 값을 구할거 같다는 생각이 들어서(아님 말고), 본 글에서는 나눗셈과 나머지 연산을 사용하여 문제를 풀었다. const solution = (input) => { let rs = input.reduce((acc, s) => acc * +s, 1); const numTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; while (rs > 0) { numTable[rs % 10]++; rs = parseInt(rs / 10); } return numTable..