๋ฐ์ํ
๋ด ํ์ด
const fs = require('fs');
let input = (fs.readFileSync('./test') + '').toString().trim().split('');
let ans = new Array(26).fill(0);
input.map((alpha) => {
let alpha2Ascii = alpha.charCodeAt(0);
ans[alpha2Ascii - 97] += 1;
});
console.log(ans.join(' '));
์ ๋ง ๋จ์ํ
๋ฐ์ ๋ฌธ์์ด์ ๋ฐฐ์ด๋ก ๋๋ฉฐ Ascii๋ก ๋ฐ๊ฟ์ฃผ๊ณ ํด๋น ๋ฐฐ์ด์ idx-97 (a = 97)์ ๋ฃ์ด์ฃผ๊ธฐ!
๋ค๋ฅธ ํ์ด
const s = require("fs").readFileSync("/dev/stdin").toString().split("");
const alphabet = "abcdefghijklmnopqrstuvwxyz";
const counts = new Array(26).fill(0);
s.forEach(i => counts[alphabet.indexOf(i)]++);
console.log(counts.join(" "));
ํธ์ค......
๋ฌธ์์ด์ ์ธ๋ฑ์ค๋ฅผ ๋ฃ์ด์ฃผ๋ ๋ฐฉ๋ฒ์ ์๊ฐ์ ๋ชปํ๋ค. ๊ตณ์ด Ascii๋ก ๋ณํํ ํ์๊ฐ ์์๋ ๋ชจ์์ ๋๋ค.
'๐ ์๊ณ ๋ฆฌ์ฆ > ๋ฐฑ์ค JS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] JS/ 11399 ATM (0) | 2021.10.06 |
---|---|
[๋ฐฑ์ค] JS/ 1157 ๋จ์ด ๊ณต๋ถ (0) | 2021.10.05 |
[๋ฐฑ์ค] JS/ 4949 ๊ท ํ์กํ ์ธ์ (0) | 2021.09.29 |
[๋ฐฑ์ค] JS/ 10798 ์ธ๋ก์ฝ๊ธฐ (0) | 2021.09.29 |
[๋ฐฑ์ค] JS/ 14561 ํ๋ฌธ (0) | 2021.09.27 |
๋๊ธ