-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16953.cpp
More file actions
49 lines (47 loc) · 930 Bytes
/
16953.cpp
File metadata and controls
49 lines (47 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 16953. A -> B
// 2020.04.28
// 브루트 포스
#include<iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int ans = 0;
// b에서 a로 이동
while (1)
{
// b와 a가 같다면 종료
if (b == a)
{
ans++;
break;
}
// b가 a보다 더 작아지면 만들 수 없는 경우
if (b < a)
{
ans = -1;
break;
}
// b의 끝이 1이면 1을 제거(10으로 나눔)
if (b % 10 == 1)
{
b /= 10;
ans++;
}
// b를 2로 나눌 수 있으면 나눔
else if (b % 2 == 0)
{
b /= 2;
ans++;
}
// 이외의 경우에는 b를 a로 만들 수 없음
else
{
ans = -1;
break;
}
}
cout << ans << endl;
return 0;
}