华为研发工程师编程题:明明的随机数
程序员文章站
2024-03-21 08:54:16
...
一、题目描述
二、解题思路
做两个bool
类型哈希表记录即可,初始化为false
,到时候遍历为真的数组元素,输出下标
#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;
}