[백준] 16562번: 친구비 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/16562 개념그래프, 분리 집합, 유니온 파인드   구현 코드(JavaScript)const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const [n, m, k] = input[0].split(' ').map((i) => +i);const friendCost = input[1].split(' ').map((i) => +i); // 친구비 입력const friendRelation = input // 친구 관계 [v, w] 입력 .slice(2) .map((real) => real.split(' ').map((i) =>..
[백준] 2108번: 통계학 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/2108개념수학, 구현구현 코드(JavaScript)const fs = require('fs');const input = fs.readFileSync(0, 'utf-8').trim().split('\n');const n = +input[0];const arr = input.slice(1).map((i) => +i);arr.sort((a, b) => a - b);// 산술평균let avg = (arr.reduce((a, c) => a + c, 0) / n).toFixed(0);console.log(avg == '-0' ? 0 : avg);// 중앙값console.log(arr[Math.floor(n / 2)]);// 최빈값const map = n..
[백준] 13904번: 과제 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/13904  개념그리디, 정렬, 우선순위 큐 코드 설명그리디 알고리즘을 이용해 풀 수 있습니다. 가장 큰 점수를 구하기 위해서는 최대한 큰 점수의 과제부터 처리하되, 가능한 가장 늦은 날짜에 배정해야만 대한 많은 과제를 수행하고 높은 점수를 얻을 수 있기 때문입니다.  문제의 요구사항을 분석하면 다음과 같습니다.하루에 한 과제만 할 수 있습니다.과제는 마감일 전에만 수행할 수 있습니다.목표는 얻을 수 있는 점수의 최댓값을 구하는 것입니다. 이를 해결하기 위한 알고리즘의 핵심 아이디어는 다음과 같습니다.정렬 방식: 점수 기준 내림차순으로 정렬합니다. 마감일에 따라 높은 점수의 과제부터 할당스케줄 배열 사용: scedule 배열을 사용하여 각 날짜..
[백준] 11659번: 구간 합 구하기 4 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/11659  개념누적 합  실행 결과1291     구현 코드(JavaScript)const fs = require('fs');// 백준 제출용let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');// 로컬 테스트용// const filePath =// process.platform === 'linux' ? '/dev/stdin' : __dirname + '/input.txt';// const input = fs.readFileSync(filePath).toString().trim().split('\n');// 백준 11659번: 구간 합 구하기 4const [n, ..
[백준] 15926번: 현욱은 괄호왕이야!! (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/15926 개념자료구조, 스택  실행 결과   구현 코드(js)const fs = require('fs');// 백준 제출용let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');// 로컬 테스트용// const filePath =// process.platform === 'linux' ? '/dev/stdin' : __dirname + '/input.txt';// let input = fs.readFileSync(filePath).toString().trim().split('\n');// 15926번 현우는 괄호왕이야!!const n = Number(input.shi..
[백준] 1914번 - 하노이 탑 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/1914  개념재귀 호출큰 수 연산  실행 결과    구현 코드(js)/*1914번 하노이 탑 자바스크립트 https://www.acmicpc.net/problem/1914오버플로우 해결 => BigInthttps://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/BigInt*/const fs = require('fs');const input = fs.readFileSync(0).toString().trim().split('\n');let n = Number(input[0]);let resArr = [];// 로컬 테스트용// const filePath =// p..
[프로그래머스] 타겟 넘버
·
PS
문제https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  개념DFS  실행 결과    구현 코드(JavaScript)function solution(numbers, target) { function dfs(index, sum) { // 다 돌았을 때 합이 target과 같으면 1, 아니면 0을 반환 if (index === numbers.length) { return sum === target ? 1 : 0; } ..
[프로그래머스] 문자열 여러 번 뒤집기
·
PS
문제https://school.programmers.co.kr/learn/courses/30/lessons/181913 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  개념문자열, 구현  실행 결과     구현 코드(JavaScript)function solution(my_string, queries) { let arr = my_string.split(""); // 쿼리 s-e만큼 반복 for (let [s, e] of queries) { // s-e만큼 자르고 뒤집기 let sub = arr.slice(s, e + 1).reverse(); ..
[프로그래머스] 주사위 게임 3
·
PS
문제  프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  개념조건문  실행 결과     구현 코드(javascript)function solution(a, b, c, d) { let count = Array(7).fill(0); // 눈금을 카운트하기 위한 배열 (1~6 사용) count[a]++; count[b]++; count[c]++; count[d]++; let score = 0; // 4개 모두 같은 경우 if (count.includes(4)) { score = 1111 * count.indexOf(4); } // 3개가 ..
자바스크립트 기초
·
Web/JavaScript
자바스크립트란? 웹의 동작을 구현하는 객체 기반 언어 온클립 속성의 값으로 옴. 객체 객체: 이름(name)과 값(value)으로 구성된 프로퍼티의 정렬되지 않은 집합 객체의 프로퍼티 참조 객체이름.프로퍼티이름 또는 객체이름["프로퍼티이름"] 객체의 메소드 참조 객체이름.메소드이름() innerHTML 프로퍼티 선택 1. HTML 태그 이름 - getElementsByTagName() 2. 아이디(id)를 이용한 선택 - getElementById() 3. 클래스(class) - getElementsByClassName() 메 4. name 속성(attribute) - getElementByName() 5. CSS 선택자(아이디, 클래스, 속성, 속성값 등) - querySelectorAll() 6. H..
생활코딩 JavaScript 객체지향 프로그래밍 (4)
·
Web/JavaScript
객체 간의 상속 var superObj = {superVal: 'super'}; var subObj = {subVal: 'sub'}; subObj.__proto__ = superObj; console.log('subObj.subVal =>', subObj.subVal); console.log('subObj.superVal =>', subObj.superVal); //.__proto__ : subObj의 부모를 superObj로! // 찾았는데 없다면, 부모에서 가져다 씀. subObj.superVal = 'sub'; console.log('superObj.superVal =>', superObj.superVal); // 자식 객체값을 바꿔도, 프로토 값은 바뀌지 않음. (얕은 복사같은 느낌!) // .b..
생활코딩 JavaScript 객체지향 프로그래밍 (3)
·
Web/JavaScript
class //class 생성 /* class Person { } var kim = new Person(); console.log(kim); */ // class constructor function class Person { constructor(name, first, second){ this.name = name; this.first = first; this.second = second; } } var kim = new Person('kim', 10, 20); console.log('kim', kim); // 출력값: kim Person { name: 'kim', first: 10, second: 20 } class constructor class Person { constructor(name, fi..