Algorithm
- 5์ 6์ ์ฐจ์ด -
๋ฌธ์
์๊ทผ์ด๋ 2863๋ฒ์์ ํ๋ฅผ ๋๋ฌด ์ด์ฌํ ๋๋ฆฐ ๋๋จธ์ง 5์ 6์ ํท๊ฐ๋ฆฌ๊ธฐ ์์ํ๋ค.
์๊ทผ์ด๊ฐ ์ซ์ 5๋ฅผ ๋ณผ ๋, 5๋ก ๋ณผ ๋๋ ์์ง๋ง, 6์ผ๋ก ์๋ชป ๋ณผ ์๋ ์๊ณ , 6์ ๋ณผ ๋๋, 6์ผ๋ก ๋ณผ ๋๋ ์์ง๋ง, 5๋ก ์๋ชป ๋ณผ ์๋ ์๋ค.
๋ ์ A์ B๊ฐ ์ฃผ์ด์ก์ ๋, ์๊ทผ์ด๋ ์ด ๋ ์๋ฅผ ๋ํ๋ ค๊ณ ํ๋ค. ์ด๋, ์๊ทผ์ด๊ฐ ๊ตฌํ ์ ์๋ ๋ ์์ ๊ฐ๋ฅํ ํฉ ์ค, ์ต์๊ฐ๊ณผ ์ต๋๊ฐ์ ๊ตฌํด ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์ ์ถ๋ ฅ ์์
๋ฌธ์ ํ๊ธฐ
let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString().split(" ");
let num1 = input[0].split('');
let num2 = input[1].split('');
let result = [];
for (let i = 0; i < Math.max(num1.length, num2.length); i++) {
if (num1[i] === '6') num1[i] = '5';
if (num2[i] === '6') num2[i] = '5';
}
result.push(Number(num1.join('')) + Number(num2.join('')));
for (let i = 0; i < Math.max(num1.length, num2.length); i++) {
if (num1[i] === '5') num1[i] = '6';
if (num2[i] === '5') num2[i] = '6';
}
result.push(Number(num1.join('')) + Number(num2.join('')));
console.log(result.join(' '));
๋ฐ์ํ
'๊ฐ์ธ๊ณต๋ถ > Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค][Node.js] 2875๋ฒ : ๋ํ or ์ธํด (0) | 2021.10.04 |
---|---|
[๋ฐฑ์ค][Node.js] 2869๋ฒ : ๋ฌํฝ์ด๋ ์ฌ๋ผ๊ฐ๊ณ ์ถ๋ค (0) | 2021.10.03 |
[๋ฐฑ์ค][Node.js] 2845๋ฒ : ํํฐ๊ฐ ๋๋๊ณ ๋ ๋ค (0) | 2021.10.01 |
[๋ฐฑ์ค][Node.js] 2839๋ฒ : ์คํ ๋ฐฐ๋ฌ (0) | 2021.09.30 |
[Level 1] 1์ฃผ์ฐจ_๋ถ์กฑํ ๊ธ์ก ๊ณ์ฐํ๊ธฐ (0) | 2021.09.29 |
๋๊ธ