我的数据结构与算法题目集代码仓:https://github.com/617076674/Data-structure-and-algorithm-topic-set
原题链接:https://pintia.cn/problem-sets/15/problems/889
题目描述:
知识点:哈希表
思路:用一个bool类型的数组filled标记某个位置是否有值,用一个int型数组nums标记存储数字
注意:输入的数字可能已经在哈希表中,这时候我们只需输出其在哈希表中的位置即可,不必插入。
C++代码:
#include<iostream>
using namespace std;
int main(){
int N, P;
scanf("%d %d", &N, &P);
bool filled[P];
fill(filled, filled + P, false);
int nums[P];
for(int i = 0; i < N;