본문 바로가기

Algorithm_BOJ(백준)/이진탐색

[백준 10815 c++ VO] 숫자 카드

728x90
반응형

- 풀이 링크: 

https://github.com/xhaktmchl/Algorithm_study/blob/main/BOJ/%EC%9D%B4%EC%A7%84%ED%83%90%EC%83%89/%5B%EB%B0%B1%EC%A4%80%2010815%20c%2B%2B%20VO%5D%20%EC%88%AB%EC%9E%90%20%EC%B9%B4%EB%93%9C.cpp

 

GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이

알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.

github.com

#include <iostream>
#include <algorithm>
//#include <map> // 중복 x 
//#include <string> // getline
//#include <cstring> // memset, strok, strstr
#include <vector>
//#include <queue>
//#include <set> // 트리, 중복 x
//#include <unordered_set>
using namespace std;
/*
[백준 10815 c++ VO] 숫자 카드
접근1: 
시간복잡도: 
풀이: 
    //1.입력
    //2.정렬
    //3.이진탐색
    //4.출력: 있으면 1, 없으면 0
*/
int n,num,m,val;
vector<int> v;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
    //1.입력
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> num;
        v.push_back(num);
    }
    //2.정렬
    //3.이진탐색
    //4.출력: 있으면 1, 없으면 0
    sort(v.begin(), v.end());
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> val;
        if (binary_search(v.begin(), v.end(), val)) cout << 1 << " ";
        else cout << 0 << " ";
    }
    return 0;
}
반응형