코딩 테스트/백준

문제https://www.acmicpc.net/problem/2668 풀이이 문제는 DFS알고리즘을 이용해 각 숫자의 사이클 여부를 확인해 답을 도출하는 문제이다. DFS 알고리즘에 사이클 시작 숫자와 현재의 숫자를 전달을 하고 해당 숫자의 값이 방문되었으며 시작 값과 같다면 정답 집합에 속하는 숫자이므로 답을 도출할 수 있다. 코드const input = require("fs") .readFileSync( process.platform === "linux" ? "/dev/stdin" : __dirname + "/example.txt" ) .toString() .trim() .split("\n") .map((e) => e.trim());const [n, ...number] = input...
문제https://www.acmicpc.net/problem/7682 풀이해당 문제에서 실수한 부분을 정리해보겠다.가로 세로에서 일자가 완성되는 경우를 측정할때, 인덱싱에서의 실수각 일자(가로 세로 대각선)을 측정할 때 "."인지 검증 하지 않은 실수일자가 하나도 안나왔을 경우 "."의 남은 개수를 고려하지 않고 모두 valid 처리한 실수위의 요소들만 주의하면 나머지 조건은 쉽게 풀린다.코드const input = require("fs") .readFileSync( process.platform === "linux" ? "/dev/stdin" : __dirname + "/example.txt" ) .toString() .trim() .split("\n") .map((e) => e.tri..
문제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/14940 코드const input = require("fs") .readFileSync( process.platform === "linux" ? "/dev/stdin" : __dirname + "/example.txt" ) .toString() .trim() .split("\n") .map((e) => e.trim());const [n, m] = input.shift().split(' ').map(Number);const map = input.map(e => e.split(' ').map(Number));const result = Array.from({ length: n }, () => Array.from({ length: m..
문제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..
58청춘
'코딩 테스트/백준' 카테고리의 글 목록