Pagini recente » Autentificare | Cod sursa (job #551126) | Cod sursa (job #1767055) | Cod sursa (job #2967066) | Cod sursa (job #1462671)
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
vector<int> v;
int findPosition(vector<int> v, int x){
bool ok = false;
int n = v.size(), i = 0;
while(i < n && ok == false){
if(v[i] == x)
ok = true;
i++;
}
if(ok == false)
return -1;
else return (i - 1);
}
void add(int x){
int found = findPosition(v, x);
if(found == -1)
v.push_back(x);
}
void removee(int x){
int position = findPosition(v, x);
if(position != -1)
v.erase(v.begin() + position);
}
int main(){
FILE *fin, *fout;
fin = fopen("hashuri.in", "r");
fout = fopen("hashuri.out", "w");
int no, op;
fscanf(fin, "%d", &no);
for(int i = 0; i < no; i++){
fscanf(fin, "%d", &op);
int x;
fscanf(fin, "%d", &x);
switch(op){
case 1: { add(x);
break;
}
case 2: { removee(x);
break;
}
case 3: { int res = findPosition(v, x);
if(res == -1)
fprintf(fout, "0\n");
else
fprintf(fout, "1\n");
break;
}
default: {}
}
}
}