분류 전체보기
-
[백준 Node.js] 2562번 최대값To infinity/Coding Practice 2021. 6. 23. 07:02
2021.06.22 Question 2562번: 최댓값 9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오. 예를 들어, 서로 다른 9개의 자연수 3, 29, 38, 12, 57, 74, 40, 85, 61 이 주어 www.acmicpc.net Answer code let fs = require('fs'); let input = (process.platform === 'linux' ? fs.readFileSync('/dev/stdin').toString() :`3 29 38 12 57 74 40 85 61`).split('\n').map(el=>+el); let max = Math.max.apply(null, input) let ord..
-
[Javascript 활용] 배열_Array.prototype.sortTo infinity/Javascript 활용 2021. 6. 22. 23:58
2021.06.22 sort 메서드 Array.prototype.sort 기능 - 배열의 요소를 정렬 - 원본배열을 직접 변경하며 정렬된 배열을 반환 (즉, 원본값을 바꾼단 의미) - 숫자타입, 문자타입 모두 정렬 가능 활용 1. 정렬을 하자 - 오름차순 정렬: default값 - 내림차순 정렬: sort로 정렬 후 reverse로 뒤집어 준다. 내림차순 정렬방법 arr.sort( ) // 먼저 오름차순 정렬 후 arr.reverse( ) // 그 다음 뒤집어 주기 ! 주의사항 ! 유니코드 포인트 순서를 따르므로 숫자타입의 경우엔 정렬순서를 정의하는 비교함수를 인수로 전달해줘야한다. 무슨소리냐하면, 문자기준으로 기본 정렬 세팅이 되어있으니 숫자기준으로 정렬하고 싶으면 어떤식으로 정렬하고 싶은지 함수한테 ..
-
[백준 Node.js] 10818번 최대값 최소값To infinity/Coding Practice 2021. 6. 22. 18:58
2021.06.22 Question 10818번: 최소, 최대 첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다. www.acmicpc.net Answer code let fs = require('fs'); let input = (process.platform === 'linux' ? fs.readFileSync('/dev/stdin').toString() :`5 20 10 35 30 7`.split('\n')); let count = Number(input[0]); let num = input[1].split(' ').map((el..
-
[백준 Node.js] 1110번 더하기 사이클To infinity/Coding Practice 2021. 6. 22. 14:29
2021.06.22 Question 1110번: 더하기 사이클 0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음, www.acmicpc.net Answer code let fs = require('fs'); let input = Number(fs.readFileSync('/dev/stdin').toString()); const result = input let count = 0; while(true){ let sum = parseInt((parseInt(input/10)) + (input % 10) %10) let num = (input % 10)*10..
-
[백준 Node.js] 10871번 X보다 작은 수 (새로운 문법 시도!)To infinity/Coding Practice 2021. 6. 21. 23:24
2021.06.21 Question 10871번: X보다 작은 수 첫째 줄에 N과 X가 주어진다. (1 ≤ N, X ≤ 10,000) 둘째 줄에 수열 A를 이루는 정수 N개가 주어진다. 주어지는 정수는 모두 1보다 크거나 같고, 10,000보다 작거나 같은 정수이다. www.acmicpc.net Answer code 1. += 연산자 사용 (얘도 forEach정도로 시간이 걸린다) let fs = require('fs'); let input =fs.readFileSync('/dev/stdin').toString().split('\n'); let X = input[0].split(' ').map((el) => +el); let A = input[1].split(' ').map((el) => +el); le..
-
[Javascript 활용] 배열_Array.prototype.joinTo infinity/Javascript 활용 2021. 6. 21. 22:48
2021.06.21 Join 메서드 Array.prototype.join 기능 원본배열의 모든 요소를 문자열로 변환 후 인수로 받은 문자열 (구분자)로 연결한 문자열을 반환. 즉, 배열 -> 구분자로 연결한 문자열로 변환. 구분자 생략가능, 기본구분자는 콤마(",") 예시 const arr = [1,2,3,4] arr.join( ); => '1,2,3,4' arr.join(' '); => '1 2 3 4'
-
[Javascript 활용] 실제로 코드를 작성해보자To infinity/Javascript 활용 2021. 6. 21. 22:35
2021.06.21 개발자는 몸을 쓰는 사람이라고 한다. 어떤 의미냐 하면 타자 위에 손을 가져다놓으면 자동적으로 코드를 입력할 정도로 숙달되어 있어야 한다는 것이다. 책을 보는 것도 좋지만 결국 실제로 직접 해봐야지 느는 것 아니겠는가. 자바스크립트에서 사용하는 문법이나 기능들을 알아야지 활용할 수 있으니 백준에서 코드연습을 하면서 하나씩 그 기능들을 익혀나가려고 한다. 계속 똑같은 방식으로 문제를 푸는 것은 의미가 없다. 똑같은 문제도 다른 방법으로 풀 수 있으니 계속 같은 문법만 사용하지 말고 여러가지 문법을 응용해보도록 하자.