https://www.acmicpc.net/problem/11656
- 사용언어 : node.js
- 알고리즘 : 문자열, 정렬
- Solved.ac Tier : Siver IV
node.js 코드
1. 문제 정리
접미사 배열 문제를 접근할 때 뒤에서 부터 하나하나 자른 문자들을 배열에 넣고, 배열에 있는 값들을 JS 내장함수인 sort를 이용하여 간단하게 해결한 문제이다.
2. 완성 코드
const filePath = process.platform === 'linux' ? '/dev/stdin' : 'ans.txt';
const input = require('fs').readFileSync(filePath).toString().trim()
const ans = new Array();
for(let i = 0; i < input.length; i++){
ans.push(input.slice(i, input.length));
}
console.log(ans.sort().join("\n"))
'백준 알고리즘 > Lang-node.js' 카테고리의 다른 글
[백준/node.js] 10845 큐 (0) | 2023.01.08 |
---|---|
[백준/node.js] 10828 스택 (0) | 2023.01.08 |
[백준/node.js] 10816 숫자 카드 2 (0) | 2023.01.04 |
[백준/node.js] 10867 중복 빼고 정렬하기 (0) | 2023.01.03 |
[백준/node.js] 10815 숫자카드 (0) | 2023.01.02 |