문제https://www.acmicpc.net/problem/15989 코드const input = require("fs") .readFileSync( process.platform === "linux" ? "/dev/stdin" : __dirname + "/example.txt" ) .toString() .trim() .split("\n") .map((e) => e.trim());const n = +input.shift();const arr = input.map(Number);const max = Math.max(...arr);const dp = Array.from({ length: max + 1 }, () => 1);let answer = "";for (let i = 2; i
백준
문제https://www.acmicpc.net/problem/20922 풀이이번 문제는 투 포인터 알고리즘을 이용한 풀이가 필요한 문제이다. 연속된 수열중 겹치는 수의 갯수를 새기위해 Map 객체를 이용해 각 숫자의 갯수를 저장하며 탐색을 진행했다. 코드const input = require("fs") .readFileSync( process.platform === "linux" ? "/dev/stdin" : __dirname + "/example.txt" ) .toString() .trim() .split("\n") .map((e) => e.trim());const [n, k] = input.shift().split(" ").map(Number);const numArr = input[0..
문제https://www.acmicpc.net/problem/20006 풀이이번 문제는 class를 이용해 풀이해 봤다.딱 보고 대기방을 클래스로 하면 정렬이나 입장과 같은 동작을 메서드로 구현해 조금 더 가독성 좋은 코드를 만들 수 있을것 같았다. 각 대기방을 클래스로 구현해두고 입장 가능 여부, 입장과 같은 동작을 메서드로 구현했다. 이번 문제를 풀며 실수했던 것은 문자열을 sort 메서드를 이용해 정렬할 때는 숫자를 정렬할때 처럼 a - b가 아니라 서로 비교연산자를 이용해야한다는 것이다.sortName() { this.nameList.sort((a, b) => { if (a[1] b[1]) return 1; });} 코드const input = require("fs") .readFil..
문제https://www.acmicpc.net/problem/12919 풀이이 문제의 경우 S 문자열 부터 T 까지 구하는것 보다, T에서 하나씩 소거하며 경우의 수를 찾는것이 더 로직을 설계하는데에 이점이 있다고 판단했다. 이러한 방법을 이용해 두 가지 로직을 구현했다.맨 뒤의 A가 있다면 맨 뒤의 A를 없애고 재귀 동작을 진행맨 앞에 B가 있다면 역순으로 바꾸고 맨 뒤에 있는 B를 제거하고 재귀 동작을 진행2번 동작에서 맨 앞의 B를 먼저 제거하지 않는 것은 문자열이 길어질 수록 JS의 shift() 메서드를 사용하면 시간 복잡도가 미세하나마 증가할 것을 우려, 완전탐색을 진행하는 메서드를 줄이기 위해 reverse() 메서드 적용뒤 pop()하여 기능을 구현했다. 코드const input = re..
문제https://www.acmicpc.net/problem/4659 풀이const input = require("fs") .readFileSync( process.platform === "linux" ? "/dev/stdin" : __dirname + "/example.txt" ) .toString() .trim() .split("\n") .map((e) => e.trim());let answer = [];const checkMou = (st) => { const aeiou = /[aeiou]/.test(st); return aeiou;};const checkTriple = (st) => { let aCnt = 0; let cnt = 0; for (let s of st) { ..
문제https://www.acmicpc.net/problem/1956 코드const input = require('fs') .readFileSync(process.platform === 'linux' ? '/dev/stdin' : __dirname + '/example.txt') .toString().trim().split('\n');const [v, e] = input.shift().split(' ').map(Number);const road = input.map(e => e.split(' ').map(Number));const village = Array.from({ length: v }, (_, idx) => Array.from({ length: v }, (__, i) => idx === i ?..