Skip to content

Commit abce8f6

Browse files
Merge pull request #208 from Coding-Crew-Forever/chaeryeon823/algorithm
[2025년 6월 셋째주 / chaeryeon823] DFS/BFS
2 parents 878d14c + 9fe6b16 commit abce8f6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

chaeryeon823/BOJ_16953.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// A->B
2+
3+
const readline = require("readline");
4+
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout,
8+
});
9+
10+
rl.on("line", (line) => {
11+
let [a, b] = line.split(" ").map(Number);
12+
let answer = 1;
13+
14+
while (b !== a) {
15+
let temp = b;
16+
if (b % 10 === 1) {
17+
b = Math.floor(b / 10);
18+
answer += 1;
19+
} else if (b % 2 === 0) {
20+
b = b / 2;
21+
answer += 1;
22+
}
23+
24+
if (b === temp) {
25+
answer = -1;
26+
break;
27+
}
28+
}
29+
30+
console.log(answer);
31+
rl.close();
32+
});

0 commit comments

Comments
 (0)