Линейный поиск

mail@pastecode.io avatar
unknown
c_cpp
a year ago
582 B
15
Indexable
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        bool flag = false;
        for (int j = 0; j < n; ++j) {
            if (a[j] == x) {
               flag = true;
               break;
            }
        }
        
        if (flag == true) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;    
}


Leave a Comment