문제와 입력
일단 전에 풀어봤던 2588번 문제를 활용해서 쉽게 풀 수 있었다.
fs로 a와 b 값을 받아 온 후 각각 백의자리, 십의자리, 일의 자리 수를 받아와서 십의 자리 수에는 10을 곱하고 일의자리 수에 100을 곱한 수를 전부 더해서 거꾸로 읽은 수를 내보내는 함수를 만들었다.
let fs = require('fs');
let [a,b] = fs.readFileSync('./dev/stdin').toString().split(' ').map(v=>parseInt(v));
function backwords(Num){
let first = Num%10*100;
let second = Math.floor((Num%100)/10)*10;
let third = Math.floor(Num/100);
return first+second+third
}
이제 backwords함수를 실행시킬때 a나 b를 넣으면 거꾸로 된 수를 받을 수 있다.
그렇게 구한 각 수를 if문을 이용해서 크기 비교 후 콘솔로 찍어줬다.
backwords(a) > backwords(b) ? console.log(backwords(a)) : console.log(backwords(b));
총 코드
더보기
let fs = require('fs');
let [a,b] = fs.readFileSync('./dev/stdin').toString().split(' ').map(v=>parseInt(v));
function backwords(Num){
let first = Num%10*100;
let second = Math.floor((Num%100)/10)*10;
let third = Math.floor(Num/100);
return first+second+third
}
backwords(a) > backwords(b) ? console.log(backwords(a)) : console.log(backwords(b));
'Coding Test' 카테고리의 다른 글
[ node.js, 자바스크립트 ] 백준 알고리즘 1330번 (0) | 2021.09.10 |
---|---|
[ node.js, javascript ] 백준 알고리즘 2588번 (0) | 2021.09.10 |
[ node.js, 자바스크립트 ] 백준 알고리즘 10430번 (0) | 2021.09.10 |
[node.js] 백준 알고리즘 자바스크립트 출력 방법 (0) | 2021.08.26 |
[node.js, javascript] 백준 알고리즘 1009번 (0) | 2021.08.26 |