mint* 2023. 2. 28. 13:57
728x90

매우 easy한 문제

 

https://www.acmicpc.net/problem/1920

 

1920번: 수 찾기

첫째 줄에 자연수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 N개의 정수 A[1], A[2], …, A[N]이 주어진다. 다음 줄에는 M(1 ≤ M ≤ 100,000)이 주어진다. 다음 줄에는 M개의 수들이 주어지는데, 이 수들

www.acmicpc.net

 

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //1. 입력받기
    set<int> s; //빠른 조회-세트 사용
    int n,m, a;
    //주어진 n개의 자연수
    cin >> n;
    while(n--){
        cin >> a;
        s.insert(a);
    }
    //조회할 m개의 자연수
    cin >> m;
    set<int>::iterator iter;
    while(m--){
        cin >> a;
        iter = s.find(a);
        if(iter !=s.end()) cout << "1\n";
        else cout <<"0\n";
    }
    
}
728x90