Pagini recente » Cod sursa (job #1517157) | Cod sursa (job #2682270) | Cod sursa (job #210959) | Cod sursa (job #3178549) | Cod sursa (job #726115)
Cod sursa(job #726115)
#include <algorithm>
#include <fstream>
#include <vector>
using namespace std;
#define MOD 666013
int nOperations;
vector <int> hash[MOD];
bool isIn(int element) {
bool isOk;
int mod;
mod = element % MOD;
isOk = find(hash[mod].begin(), hash[mod].end(), element) != hash[mod].end();
return isOk;
}
void add(int element) {
int mod;
if (!isIn(element)) {
mod = element % MOD;
hash[mod].push_back(element);
}
}
void remove(int element) {
int mod;
vector<int>::iterator it;
if (isIn(element)) {
mod = element % MOD;
it = find(hash[mod].begin(), hash[mod].end(), element);
hash[mod].erase(it);
}
}
int main() {
ifstream fin ("hashuri.in" );
ofstream fout("hashuri.out");
int element, operation;
fin >> nOperations;
while (nOperations--) {
fin >> operation;
switch (operation) {
case 1 :
fin >> element;
add(element);
break;
case 2 :
fin >> element;
remove(element);
break;
case 3 :
fin >> element;
fout << isIn(element) << "\n";
break;
}
}
return 0;
}