
const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'Wiki\\input.txt';
const s = fs.readFileSync(path).toString().trim();
const answer = [];
for (let i = 97; i < 123; i++) {
answer.push(s.indexOf(String.fromCharCode(i)));
}
console.log(...answer);
⏰ 소요한 시간 : -
a의 아스키 코드는 97이다. 그래서 97부터 z의 아스키코드인 122까지 String.fromCharCode(i) 메서드를 사용해 각 요소를 숫자에서 알파벳으로 변경해준다. 그 후 indexOf 메서드로 위치 정보를 출력해주면 된다. indexOf 메서드는 알파벳이 문자열에 포함되어 있지 않다면 자동으로 -1을 반환한다.