๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ์ธ๊ณต๋ถ€/Algorithm

[๋ฐฑ์ค€][Node.js] 2864๋ฒˆ : 5์™€ 6์˜ ์ฐจ์ด

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2021. 10. 2.

 

 

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(' '));

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€