๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ๐Ÿฃ: ๐’œ๐“๐‘”๐‘œ๐“‡๐’พ๐“‰๐’ฝ๐“‚/์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€์ด

BOJ13777 : Hunt The Rabbit

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>

using namespace std;

void binary(int first, int end, int target)
{
    if (first > end)
        return;
    int mid = (first + end) / 2;
    cout << mid << " ";
    if (mid == target)
        return;
    if (mid < target)
        binary(mid + 1, end, target);
    else
        binary(first, mid - 1, target);
}

int main()
{
    int target[50];
    int i;
    for (i = 0; i < 50; i++)
    {
        cin >> target[i];
        if (target[i] == 0)
            break;
    }
    for (int j = 0; j < i; j++)
    {
        binary(1, 50, target[j]);
        cout << "\n";
    }
    return 0;
}