Huawei's R & D engineers programming problem: obviously random number

One, Title Description

Here Insert Picture Description
Here Insert Picture Description

Second, problem-solving ideas

Do two booltypes of hash table records can be initialized to false, the traversal is true to the array elements, output index

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{

    unsigned int N1, N2;
    vector<bool> Hash1(1001, false);
    vector<bool> Hash2(1001, false);
    cin >> N1;
    unsigned int tmp;
    for (unsigned int i = 0; i < N1; i++)
    {
        cin >> tmp;
        Hash1[tmp] = true;
    }
    cin >> N2;
    for (unsigned int i = 0; i < N2; i++)
    {
        cin >> tmp;
        Hash2[tmp] = true;
    }
    for (unsigned int i = 0; i < 1001; i++)
    {
        if (Hash1[i] == true)
            cout << i << endl;
    }
    for (unsigned int i = 0; i < 1001; i++)
    {
        if (Hash2[i] == true)
            cout << i << endl;
    }
    return 0;
}

Third, the operating results

Here Insert Picture Description

Published 30 original articles · won praise 3 · Views 812

Guess you like

Origin blog.csdn.net/weixin_44587168/article/details/105370306