Notice
Recent Posts
Recent Comments
«   2025/05   »
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
Today
Total
Archives
관리 메뉴

cyphen156

백준-집합과 맵 10815 숫자 카드 본문

컴퓨터공학/알고리듬 풀이

백준-집합과 맵 10815 숫자 카드

cyphen156 2025. 4. 30. 12:13

숫자 카드

N개의 카드 중 M개의 입력에 대해 존재 유무를 찾는 프로그램 작성하기

제약사항

  • 0 < N <= 500,000
  • -100,000 <= NInput ≤ 100,000
  • 0 < M <= 500,000
  • -100,000 <= MInput ≤ 100,000
  • return Value (Yes :: 1, No :: 0)

주의 사항

없다.

CPP풀이

숫자 카드_10815.cpp

/**
 * 백준 숫자 카드_10815
 * N개의 카드 중 M개의 입력에 대해 존재 유무를 찾는 프로그램 작성하기
 * 
 * 제한사항
 *****************************************
 * 0 < N <= 500,000                      *
 * -100,000 <= NInput ≤ 100,000          *
 * 0 < M <= 500,000                      *
 * -100,000 <= MInput ≤ 100,000          *
 * return Value (Yes :: 1, No :: 0)      *
 *****************************************
 *
 *
 *
 * 주의
 * 없다.
 * 
 * 풀이시간 5분
 */


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;

    vector<int> NInputs;
    for (int i = 0; i < N; ++i)
    {
        int input;
        cin >> input;
        NInputs.push_back(input);
    }

    sort(NInputs.begin(), NInputs.end());

    int M;
    cin >> M;
    for (int i = 0; i < M; ++i)
    {
        int input;
        cin >> input;
        if (binary_search(NInputs.begin(), NInputs.end(), input))
        {
            cout << 1; 
        }
        else
        {
            cout << 0;
        }
        cout << ' ';
    }
    cout << endl;
    return 0;
}

모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리 에 있습니다.

 

Workspace/알고리듬 풀이 at main · cyphen156/Workspace

Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.

github.com