콘솔창 & 윈도우창/코딩 테스트

프로그래머스 LV.2 예상 대진표

뽀또치즈맛 2025. 3. 23. 22:00

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;
}

 

 

 

GitHub :
https://github.com/kwon1232/CodingTest/tree/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/2/12985.%E2%80%85%EC%98%88%EC%83%81%E2%80%85%EB%8C%80%EC%A7%84%ED%91%9C