Gidhub BE Developer

[BOJ] 10816. 숫자 카드2

2018-09-26
goodGid

Problem

Problem URL : 숫자 카드2


[1] Answer Code (18. 09. 26)

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(void) {
    int n;
    scanf("%d", &n);
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int num;
        scanf("%d", &num);
        v.push_back(num);
    }
    sort(v.begin(), v.end());
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int num;
        scanf("%d", &num);
        if (binary_search(v.begin(), v.end(), num) == 0) {
            printf("0 ");
        }
        else{
            printf("%ld ", upper_bound(v.begin(), v.end(), num) - lower_bound(v.begin(), v.end(), num));
        }
    }
}

Review


Recommend

Index