-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash.cpp
More file actions
75 lines (70 loc) · 1.55 KB
/
Hash.cpp
File metadata and controls
75 lines (70 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
using namespace std;
/*
n = quantidade de casos teste
m = quantidade de endereços na tabela
c = quantidade de chaves a serem armazenadas
*/
int main(){
int n; //quantidade de casos teste
cin>>n;
while(n--){
int m; //m = quantidade de endereços da tabela
int c; //c = quantidade de chaves a serem armazenadas
cin>>m>>c;
int vet[c]; //vetor p/ armazenar as chaves
for(int i=0; i<c; i++){
cin>>vet[i]; //coleta as chaves
}
for(int j=0; j<m; j++){ //exibe as posições da tabela hash
cout<<j<<" -> ";
for(int k=0; k<c; k++){
if(vet[k]%m == j){ //faz a comparação do resto com a posição da tabela
cout<<vet[k]<<" -> ";
}
}
cout<<"\\";
if((n != 0) || (j < m-1)){
cout<<endl;
}
}
//if(n != 0){
cout<<endl;
//}
}
}
/*
int main()
{
int n; //quantidade de casos teste
cin>>n;
bool x=false;
while(n--)
{
if(x)
{
cout<<endl;
}
else
x=true;
int m,c; //m = quantidade de endereços na tabela; c = quantidade de chaves a serem armazenadas
cin>>m>>c;
int v[c],i=0;
for(int j=0;j<c;j++)
cin>>v[j];
for(i=0;i<m;i++)
{
cout<<i<<" -> ";
for(int j=0;j<c;j++){
//cout<<i<<" ->";
if(v[j]%m==i)
cout<<v[j]<<" -> ";
//if(i+1==m)
//cout<<" \n";
}
cout<<"\n";
}
}
return 0;
}
*/