How to find all the repetitive values in the MAP container? C++.
Display only repetitive values, their keys and the number of repetitions
Answer 1, Authority 100%
Get one more mapp
std :: map & lt; int, std :: vector & lt; int & gt; & gt;
just put the value, and in the vector keys where they appear
Here is an example code:
# include & lt; Cstdlib & gt;
#Include & lt; iostream & gt;
#Include & lt; Map & GT;
#Include & lt; vector & gt;
INT MAIN () {
STD :: MAP & LT; INT, INT & GT; m {{1, 1}, {2, 9}, {3, 1},
{4, 2}, {5, 2}, {6, 3}
};
STD :: MAP & LT; INT, STD :: Vector & LT; int & gt; & gt; RET {};
For (Const Auto & Amp; V: M) {
RET [v.second] .push_back (v.first);
}
For (Const Auto & Amp; V: RET) {
if (v.second.size () & gt; 1) {
STD :: COUT & LT; & LT; V.First & LT; & LT; ":";
For (Const Auto & Amp; VV: v.second) {
STD :: COUT & LT; & LT; VV & LT; & LT; "";
}
STD :: COUT & LT; & LT; STD :: ENDL;
}
}
Return EXIT_SUCCESS;
}