20250827 baekjoon

This commit is contained in:
songyc macbook 2025-08-27 20:58:20 +09:00
parent 714cba765e
commit 8424b1dca2
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,29 @@
#include <stdio.h>
int main() {
int A, B;
scanf("%d %d",&A, &B);
int flag = 0;
int count = 1;
while(B >= A) {
if (A==B) {
flag = 1;
break;
}
if (B%2==0) {
B /= 2;
count++;
}
else if (B%10==1) {
B /= 10;
count++;
}
else break;
}
printf("%d\n", flag ? count : -1);
return 0;
}

View File

@ -0,0 +1,27 @@
if let input = readLine(), let nums = input.split(separator: " ").compactMap({Int($0)}) as? [Int], nums.count == 2 {
let A: Int = nums[0]
var B: Int = nums[1]
var count: Int = 1
var flag: Bool = false
while B >= A {
if A == B {
flag = true
break
}
if B%2 == 0 {
B /= 2
count+=1
}
else if B%10 == 1 {
B = (B-1)/10
count+=1
}
else {
break
}
}
print(flag ? count : -1)
}