Algorithm
- ์ฑ๊ธฐํ ๋ค์๋ฆฌ ์ซ์ -
๋ฌธ์
์ฑ๊ธฐํ ๋ค์๋ฆฌ ์ซ์๋, [1000,9999]์ธ 10์ง์ ์ซ์์ค์์, ๋ค์์ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์ซ์๋ฅผ ๋งํ๋ค.
- ์ซ์๋ฅผ 10์ง์, 12์ง์, 16์ง์๋ก ๋ํ๋ธ ๋ค์, ๊ฐ๊ฐ์ ์ซ์์ ๋ํด, ๊ฐ ์ซ์์ ์๋ฆฌ์๋ฅผ ๋ํ์ ๋, ์ธ ๊ฐ์ด ๋ชจ๋ ๊ฐ์์ผ ํ๋ค.
์ฌ๋ฌ๋ถ์ ์ฑ๊ธฐํ ๋ค์๋ฆฌ ์ซ์๋ฅผ ๋ชจ๋ ์ถ๋ ฅํด์ผ ํ๋ค.
์ ์ถ๋ ฅ ์์
๋ฌธ์ ํ๊ธฐ
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", function () {}).on("close", function () {
for (let i = 1000; i <= 9999; i++) {
let ten = 0;
let twelve = 0;
let sixteen = 0;
let number = i;
while (number !== 0) {
ten += number % 10;
number = Math.floor(number / 10);
}
number = i;
while (number !== 0) {
twelve += number % 12;
number = Math.floor(number / 12);
}
number = i;
while (number !== 0) {
sixteen += number % 16;
number = Math.floor(number / 16);
}
if (ten === twelve && twelve === sixteen) console.log(i);
}
process.exit();
});
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 7567๋ฒ : ๊ทธ๋ฆ (0) | 2021.12.08 |
---|---|
[๋ฐฑ์ค][Node.js] 7287๋ฒ : ๋ฑ๋ก (0) | 2021.12.07 |
[๋ฐฑ์ค][Node.js] 6603๋ฒ : ๋ก๋ (0) | 2021.12.04 |
[๋ฐฑ์ค][Node.js] 6359๋ฒ : ๋ง์ทจํ ์๋ฒ (0) | 2021.12.03 |
[๋ฐฑ์ค][Node.js] 6064๋ฒ : ์นด์ ๋ฌ๋ ฅ (0) | 2021.12.02 |
๋๊ธ