Hello, well it sounds more like an algorythmic problem, but maybe there is a built-in function already or something similar, if not I'd appreciate any help ;).
Basically the problem sounds simple, we have an array of X elements and we have to find out how many elements in that array occur more than one time, in example :
1 2 3 4 5 6 7 8 9 10 11 12
|
a
a
b
c
d
e
f
e
c
g
h
j
|
The elements that occur one than more time are : a+c+e - therefore
the outcome =3.
I tried something like this :
1 2 3 4 5 6 7 8 9 10
|
int h=0;
int elementcount=0;
vector<string> vs; // lets say it already contains x amount of strings in //seperated lines
for(int i = 0; i < vs.size(); i++){
for(int j = 0; j < vs.size(); j++){
if(vs[i]==vs[j] && i!=j){
h++;
}
}if(h>0){elementcount++; h=0;}
}
|
The problem with this solution is simple - it counts all the elements instead of just one case of a specific argument, for example :
a+a+c+c+e+e - > the outcome = 6.
I thought about making another container for the elements that already occured earlier on which would automatically exclude them from incrementing elementcount, but hell... that sounds a bit "too" complicated for such a "simple" problem, do you guys have any advices / thoughts of better solutions ?