Pagini recente » Cod sursa (job #3216618) | Cod sursa (job #3191149) | Cod sursa (job #2764992) | Cod sursa (job #2083450) | Cod sursa (job #2193174)
#include <stdio.h>
#include <vector>
#define SEED 666013
using namespace std;
int N;
vector<int> valuesSet[SEED];
vector<int>::iterator search(int value, int listIndex) {
vector<int>::iterator it;
for (it = valuesSet[listIndex].begin(); it != valuesSet[listIndex].end(); it++) {
if (*it == value) { return it; }
}
return valuesSet[listIndex].end();
}
int main() {
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int operation, parameter;
scanf("%d", &N);
int counter = 0;
while ( N > 0) {
scanf("%d %d", &operation, ¶meter);
int listIndex = parameter % SEED;
if (operation == 1) {
// insert into set
if (search(parameter, listIndex) == valuesSet[listIndex].end()) {
valuesSet[listIndex].push_back(parameter);
}
}
if (operation == 2) {
// delete from set
vector<int>::iterator position = search(parameter, listIndex);
if (position != valuesSet[listIndex].end()) {
valuesSet[listIndex].erase(position);
}
}
if (operation == 3) {
// query the set for parameter's existence
printf("%d\n", search(parameter, listIndex) != valuesSet[listIndex].end());
}
N --;
}
return 0;
}