https://school.programmers.co.kr/learn/courses/30/lessons/12985
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
#include <iostream>
using namespace std;
int solution(int n, int a, int b)
{
int answer = 0;
while(a != b)
{
// %2 를 더해준 이유는 홀수일 경우를 위해서이다.
a = (a/2) + (a%2);
b = (b/2) + (b%2);
answer++;
}
return answer;
}
'콘솔창 & 윈도우창 > 코딩 테스트' 카테고리의 다른 글
프로그래머스 LV.3 야근 지수 (0) | 2025.03.31 |
---|---|
프로그래머스 LV.2 롤케이크 자르기 (0) | 2025.03.30 |
백준 실버4 1920 수 찾기 (1) | 2024.12.26 |
프로그래머스 LV.2 전화번호 목록 (2) | 2024.12.24 |
프로그래머스 LV.2 모음사전 (1) | 2024.12.14 |