SWUST数据结构--哈希表(链地址)

#include<iostream>
using namespace std;

struct node {
	int data[100];
	int top;
};

int main()
{
	node a[100];
	int n,m,i,tmp,wait;
	cin>>n>>m;
	for(i=0;i<n;i++)
		a[i].top = -1;
	for(i=0;i<m;i++)
	{
		cin>>tmp;
		a[tmp%n].top++;
		a[tmp%n].data[a[tmp%n].top] = tmp;
	}
	cin>>wait;
	for(i=0;i<=a[wait%n].top;i++)
	{
		if(a[wait%n].data[i] == wait) break;
	}
	if(i>a[wait%n].top) cout<<"-1";
	else cout<<wait%n<<","<<i+1;
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41681743/article/details/80799626