250x250
Notice
Recent Posts
Recent Comments
Link
\(@^0^@)/
[JS] ๋ฐฑ์ค 2577๋ฒ ์ซ์์ ๊ฐ์ ๋ณธ๋ฌธ
728x90
๐ฑ๐ 1. ๋ฌธ์ : 2577
https://www.acmicpc.net/problem/2577
๐ฅ 2.1 split์ ์ด์ฉํ ์ฝ๋
const fs = require('fs');
const file = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
// Num์ผ๋ก ๋ฐ๊ฟ์ผ ๊ณต๋ฐฑ์์ด ์ ๋๋ก ๋น๊ต ๊ฐ๋ฅ.
let input = fs.readFileSync(file).toString().split('\n').map(n => Number(n));
let first = input[0];
let sec = input[1];
let third = input[2];
let multi = String(first * sec * third);
// ๊ฐ๊ฒฐํ๊ฒ let multi = String(input[0] * input[1] * input[2]) ์ด๋ ๊ฒ ํ ์๋ ์์!
for (let i = 0; i <= 9; i++) { // i < 10์ ์ฐ๊ธฐ๋ ํจ. (2.2 ์ฐธ๊ณ )
// console.log(multi.split(i + '').length) ์ด๋ ๊ฒ๋ง ํ๋ค๋ฉด,
// 1-9๊น์ง๊ฐ ์๋๋ผ, 0-9๊น์ง์ ์ซ์๋ฅผ ๊ตฌํ๊ฒ ๋๋ฏ๋ก, -1์ ํด์ค๋ค.
console.log(multi.split(i + '').length -1)
}
๐ฅ 2.2 ์ค์ฒฉ for๋ฌธ์ ์ด์ฉํ ์ฝ๋
const fs = require('fs');
const file = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
// Num์ผ๋ก ๋ฐ๊ฟ์ผ ๊ณต๋ฐฑ์์ด ์ ๋๋ก ๋น๊ต ๊ฐ๋ฅ.
let input = fs.readFileSync(file).toString().split('\n').map(n => Number(n));
let multi = String(input[0] * input[1] * input[2]);
// for๋ฌธ์์ ๊ตฌํ multi[]๊ฐ์ด i์ ์ผ์นํ๋ค๋ฉด count๊ฐ์ ์ฌ๋ ค์ค.
let count;
for (let i = 0; i <= 9; i++) {
count = 0;
for(let j = 0; j < multi.length; j++) {
if(multi[j] == i) {
// Number(multi[j] === i) ๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ๋ ์์.
count++;
}
}
console.log(count);
}
728x90
'์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] ๋ฐฑ์ค 8958๋ฒ OXํด์ฆ (0) | 2021.09.28 |
---|---|
[JS] ๋ฐฑ์ค 3052๋ฒ ๋๋จธ์ง (0) | 2021.09.28 |
[JS] ๋ฐฑ์ค 1110๋ฒ ๋ํ๊ธฐ ์ฌ์ดํด (0) | 2021.09.24 |
[JS] ๋ฐฑ์ค 10952๋ฒ A+B - 5 (0) | 2021.09.24 |
[JS] ๋ฐฑ์ค 2439๋ฒ ๋ณ ์ฐ๊ธฐ - 2 (0) | 2021.09.17 |