Pagini recente » Cod sursa (job #3152547) | Cod sursa (job #2704215) | Cod sursa (job #31416) | Cod sursa (job #123000) | Cod sursa (job #760304)
Cod sursa(job #760304)
#include <fstream>
#include <vector>
#include <set>
static const unsigned int HASH_KEY(666013);
inline unsigned int hash (unsigned int number)
{
return number % HASH_KEY;
}
typedef std::set<unsigned int> store_hash;
typedef std::vector<store_hash> hash_table;
inline bool search_hash (const hash_table &table, const unsigned int number)
{
return table[hash(number)].find(number) != table[hash(number)].end();
}
inline void hash_add (hash_table &table, const unsigned int number)
{
table[hash(number)].insert(number);
}
inline void hash_remove (hash_table &table, const unsigned int number)
{
table[hash(number)].erase(number);
}
int main (void)
{
unsigned int data_size;
std::ifstream input("hashuri.in");
input >> data_size;
char operation;
unsigned int number;
hash_table table(HASH_KEY);
std::ofstream output("hashuri.out");
do
{
input >> operation >> number;
if (operation == '1')
hash_add(table,number);
else if (operation == '2')
hash_remove(table,number);
else
{
if (search_hash(table,number))
output.put('1');
else
output.put('0');
output.put('\n');
}
--data_size;
}
while (data_size);
input.close();
output.close();
return 0;
}