I have two vectors of the form std::vector<int> a
and std::vector<int> b
, for example
a= 1,2,3,3,4,5,6;
b=0.1, 0.3, 0.2, 0.5, 0.6, 0.1, -0.2;
both vectors are of the same size and in fact they work like a XY pair ((1,0.1) , (2,0.3)...etc)
. Mercifully, a
is sorted from less to more always
I want to find the duplicates in the first vector and then erase the first of them, in my example the output should be:
a= 1,2,3,4,5,6;
b=0.1, 0.3, 0.5, 0.6, 0.1, -0.2;
in MATLAB I would do something like this:
b(find(diff(a) == 0)) = [];
a(find(diff(a) == 0)) = [];
I know I can do it the old fashioned way using for loops and if statements but I am sure there is a more elegant way to do it in c++ with containers and iterators. Searching the internet there is plenty of examples for erasing the duplicate in the first vector but not of using the same indexes to erase the elements in the second vector.
Any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire