์๊ณ ๋ฆฌ์ฆ
[JS] ๋ฐฑ์ค 10809 ์ํ๋ฒณ ์ฐพ๊ธฐ
minjuuu
2021. 10. 11. 17:19
728x90
๐ฑ๐ 1. ๋ฌธ์ : 10809
https://www.acmicpc.net/problem/10809
๐ฅ 2. ์ฝ๋ ๋ฐ ํ์ด
const fs = require('fs');
const file = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(file).toString().split('\n');
let str = input[0];
const result = [];
// ์์คํค ์ฝ๋์์ a-z๋ 97-122๊น์ง 97-122์ ๋ฒ์๋ฅผ ๋๋ฉด์,
// String.fromCharCode => ๋ฉ์๋๋ฅผ ์ฌ์ฉํด์ a-z๊น์ง์ ์ํ๋ฒณ์ ์์ฑ,
// str.indexOf => ๋ฐฐ์ด์ ํด๋น ๊ฐ์ด ์๋ค๋ฉด ๊ทธ ๊ฐ์ index๋ฅผ ๋ฃ์ (๋ฐฐ์ด์ ํด๋น ๊ฐ์ด ์๋ค๋ฉด, -1์ด ์ ์ ๋ก ์ถ๋ ฅ๋จ)
// result.push => push ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ result ๋ฐฐ์ด์ ์ถ๊ฐ.
for (let i = 97; i <= 122; i++) {
result.push(str.indexOf(String.fromCharCode(i)))
}
// join์ผ๋ก ๊ณต๋ฐฑ์ ์ค์, ์ถ๋ ฅ ํ์ ๋ง์ถ๊ธฐ
console.log(result.join(" "));
728x90