let fs = require('fs');
let path = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
let input = fs.readFileSync(path).toString().trim();
function solve(input) {
let answerArray = new Array();
for (i = 97; i <= 122; i++) {
let alphabet = String.fromCharCode(i);
if (input.includes(alphabet)) {
for (j = 0; j < input.length; j++) {
let str = input[j];
if (alphabet === str) {
answerArray.push(j);
break;
}
}
} else {
answerArray.push(-1);
}
}
return answerArray;
}
console.log(...solve(input));
๋จผ์ ์์ผ๋ก ํ์คํ ์์๋ const ๋ฐ ๋๋ฌธ์(์ค๋ค์ดํฌ๊ธฐ๋ฒ)๋ก ์ ์ธํด์ฃผ์! ex) const MAX_NUMBER = 1000;
๊ทธ๋ฆฌ๊ณ ์์๊ฐ ์๋ ๋ณ์๋ let ๋ฐ ์๋ฌธ์(camelCase)๋ก ์ ์ธํ๋๋ก ์ฐ์ตํ์!
์ ๋ฌธ์ ์ ๊ฒฝ์ฐ, ์์คํค ์ฝ๋๋ฅผ ํ์ฉํ์ฌ a~z๊น์ง๋ฅผ ๋ฐ๋ณต๋ฌธ์ ํตํด ์ป์ด๋ด๊ณ ๊ทธ ๊ฐ์ ์ฃผ์ด์ง ์
๋ ฅ๊ฐ์ ๊ฐ ์๋ฆฌ์ ๋น๊ตํ๋ฉด์
๋น ๋ฐฐ์ด์ ์กฐ๊ฑด์ ๋ง๋ ๊ฐ๋ค์ ๋ฃ์ด์ฃผ๋ ๊ฒ์ด ํต์ฌ
๋ํ ์ค๋ณต๋ ์ํ๋ฒณ์ด ์๋ ๊ฒฝ์ฐ๋ฅผ ๋๋นํด์ break๋ฅผ ์จ์ค๋ค.
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 1157 (0) | 2022.05.17 |
---|---|
[JS] 2675 (0) | 2022.05.17 |
[JS] 1065 (0) | 2022.05.15 |
[JS] 4673 (0) | 2022.05.15 |
[JS] 10818 (0) | 2022.05.14 |