0
找到最常見的值(頻率最高)。如果兩個(或更多)的值具有相同的頻率選擇其中一個隨機最常見的值C++使用map
我需要用隨機位
map<int, int > myp;
int con = 0;
for (int h = 0; h < distan.size(); h++) {
con = (int) count(distan.begin(), distan.end(), distan[h]);
myp.insert(pair<int, int> (con, distan[h]));
}
//getting the highest frequency value
int max = 0;
int temp_max = max;
max = max_element(myp.begin(), myp.end())->first;
cout<<con<<endl;
data_labels.push_back(myp[max]);
myp.clear();
'myp','con' ,'distan' ...使用*描述性*名稱。 –