티스토리 뷰

#include <iostream>
#include <vector>

using namespace std;

vector<int> A;

int binary(int t, int start, int end)
{
    int mid = (start + end)/2;

    if (start > end)return 0;
    if(t == A[mid])return 1;
    else if(t > mid)start = mid;
    else end = mid;

    binary(t, start+1, end);
    return 0;
}
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int ipt;
        cin >> ipt;
        A.push_back(ipt);
    }
    int target;
    cin >> target;
    cout <<binary(target, 0, n-1);
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함