๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”‘ ์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฐฑ์ค€ JS

[๋ฐฑ์ค€] JS/ 10808 ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜

by Tamii 2021. 9. 30.
๋ฐ˜์‘ํ˜•

๋‚ด ํ’€์ด

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๋กœ ๋ณ€ํ™˜ํ•  ํ•„์š”๊ฐ€ ์—†์—ˆ๋˜ ๋ชจ์–‘์ž…๋‹ˆ๋‹ค.

๋Œ“๊ธ€