diff --git a/code_study/Baekjoon/c/16953.c b/code_study/Baekjoon/c/16953.c new file mode 100644 index 0000000..650c951 --- /dev/null +++ b/code_study/Baekjoon/c/16953.c @@ -0,0 +1,29 @@ +#include + +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; +} \ No newline at end of file diff --git a/code_study/Baekjoon/swift/16953.swift b/code_study/Baekjoon/swift/16953.swift new file mode 100644 index 0000000..56e56ab --- /dev/null +++ b/code_study/Baekjoon/swift/16953.swift @@ -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) +} \ No newline at end of file