코딩테스트/프로그래머스
[Level 2][C++] 예상 대진표
MJ.Lee
2024. 10. 1. 12:47
#include <iostream>
using namespace std;
int giveNum(int a)
{
if(a%2==0)
return a/2;
else
return a/2+1;
}
int tornumant(int a, int b)
{
if(a==b)
return 0;
a = giveNum(a);
b = giveNum(b);
return 1+tornumant(a, b); //토너먼트 치룰 때 마다 1씩 증가.
}
int solution(int n, int a, int b)
{
return tornumant(a,b);
}
반복문으로 2를 계속 나눠서 같은 숫자가 나올 때까지 카운트 해도 되는데,
재귀함수를 활용해보고 싶어서 재귀함수로 풀었다.