vendredi 26 août 2016

Algorithm for finding most present value in containers

I have the following problem I have a vector of std::set's now I want to compute the element, which is in the most of the sets. For example: If the sets are {1,2,3,4}, {2,4,5} and {2,7,8} i want the algorithm to output 2, because 2 is in 3 sets and every other element isnt. My current attempt in solving this uses a map, which maps a counter tovevery value in the sets and then iterates over all the sets. I am sure I need to iterate over all the sets, but can I solve this using some algorithms in the <algorithm> header?

Aucun commentaire:

Enregistrer un commentaire