Pagini recente » Cod sursa (job #688689) | Cod sursa (job #119823) | Cod sursa (job #915722) | Cod sursa (job #2656379) | Cod sursa (job #3232523)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
///hashuri
class Hash
{
public:
int n;
list<int> *H;
list<string> *Hs;
Hash(int n)
{
this->n = n;
H = new list<int>[n + 5];
Hs = new list<string>[n + 5];
}
~Hash()
{
delete []H;
delete []Hs;
}
int Modulo(int x)
{
return x % n;
}
int Modulo_String(string x)
{
int i;
sum = 0;
for(i=0;x[i]!=0;i++)
sum += (x[i] - 'a');
return sum % n;
}
void Insert(int x)
{
int index = Modulo(x);
H[index].push_back(x);
}
void Insert_String(string x)
{
int index = Modulo_String(x);
Hs[index].push_back(x);
}
void Delete(int x)
{
int index = Modulo(x);
list <int> :: iterator it;
for (it = H[index].begin(); it != H[index].end() && *it != x; it++)
;
if(it != H[index].end()) H[index].erase(it);
}
void Delete_String(string x)
{
int index = Modulo_String(x);
list <string> :: iterator it;
for (it = Hs[index].begin(); it != Hs[index].end() && *it != x; it++)
;
if(it != Hs[index].end()) Hs[index].erase(it);
}
void Afisare()
{
int i;
for (i = 0; i < n; i++)
{
for (auto w : H[i])
fout << w << " ";
fout << "\n";
}
}
void Afisare_String()
{
int i;
for (i = 0; i < n; i++)
{
for (auto w : Hs[i])
fout << w << " ";
fout << "\n";
}
}
bool Find(int x)
{
int index = Modulo(x);
list<int>::iterator it;
for (it = H[index].begin(); it != H[index].end(); it++)
if (*it == x) return true;
return false;
}
bool Find_String(string x)
{
int index = Modulo_String(x);
list<string>::iterator it;
for (it = Hs[index].begin(); it != Hs[index].end(); it++)
if (*it == x) return true;
return false;
}
};
int main()
{
Hash A(1234577);
int op, n, i;
string x;
cin >> n;
for(i=1; i<=n; i++)
{
cin >> op >> x;
A.Insert_String(x);
}
cin >> n;
while(n--)
{
A..h
}
return 0;
}