Home > Back-end >  One of the problems with the STL, for help
One of the problems with the STL, for help

Time:09-16

Using the vector n integers stored user input from the keyboard, use of the STL algorithms, data statistical occurrences is greater than 2,

CodePudding user response:

Vector ,2,3,4,5,6,7,2,3,0,10 v={1};
Cout & lt; Return the count & gt; 2;
});

CodePudding user response:

Look at this time, a little taste of dlut

CodePudding user response:

 int main () {
int n;
Cin & gt;> n;//enter data into a total of how much
Vector Vec.//save data
Int number;
//from the keyboard input number n
While (n -) {
Cin & gt;> Number;
Vec. Push_back (number);
}
Unordered_map & lt; Int, int> Num_count;
//statistics the number of occurrences of the
For (auto & amp; It: vec) {
{if (num_count. Count (it))
Num_count [it] + +;
}
The else {
Num_count. Insert (pair (it, 1));
}
}
//output
For (auto & amp; It: num_count) {
If (it. The second & gt; 2) {
Cout & lt; }
}

}


Example: input the number 7, including 22 appeared 3 times,
  • Related