Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to find the most frequent value of string array, and how many Pin
sadas232341s20-Nov-11 6:26
sadas232341s20-Nov-11 6:26 
GeneralRe: How to find the most frequent value of string array, and how many Pin
Chris Losinger20-Nov-11 6:35
professionalChris Losinger20-Nov-11 6:35 
GeneralRe: How to find the most frequent value of string array, and how many Pin
sadas232341s20-Nov-11 7:03
sadas232341s20-Nov-11 7:03 
GeneralRe: How to find the most frequent value of string array, and how many Pin
Chris Losinger20-Nov-11 7:20
professionalChris Losinger20-Nov-11 7:20 
GeneralRe: How to find the most frequent value of string array, and how many Pin
sadas232341s20-Nov-11 8:21
sadas232341s20-Nov-11 8:21 
GeneralRe: How to find the most frequent value of string array, and how many Pin
sadas232341s4-May-12 21:27
sadas232341s4-May-12 21:27 
GeneralRe: How to find the most frequent value of string array, and how many Pin
Chris Losinger5-May-12 1:31
professionalChris Losinger5-May-12 1:31 
GeneralRe: How to find the most frequent value of string array, and how many Pin
Randor 20-Nov-11 11:12
professional Randor 20-Nov-11 11:12 
TCPMem wrote:
I did it. Now how to see which element repeats the most and how many times?


TCPMem,

Rather than re-inventing those algorithms... just use the ones supplied by the c++ language.

C++
string str[8] = {"zxc", "zxc", "asd", "qwe", "zxc", "asd", "qwe", "jkl"};
vector<string> v_strAll;
vector<string> v_strUnique;
list<pair<string,size_t>> counts;

v_strAll.assign(str,str+_countof(str));
sort(v_strAll.begin(),v_strAll.end());
unique_copy(v_strAll.begin(),v_strAll.end(),back_inserter(v_strUnique));

std::vector<string>::iterator it = v_strUnique.begin();
while(it != v_strUnique.end())
{
	counts.push_back(make_pair(*it,count_if(v_strAll.begin(),v_strAll.end(),[it](const std::string& s1){return s1 == *it;})));
	++it;
}


Heh, if you really want to annoy the guy reviewing your code... you can get rid of that while loop and use a dual lambda if your compiler supports it.

C++
for_each(v_strUnique.begin(),v_strUnique.end(),[&counts,v_strAll](const std::string& str){counts.push_back(make_pair(str,count_if(v_strAll.begin(),v_strAll.end(),[str](const std::string& s1){return s1 == str;})));});

GeneralRe: How to find the most frequent value of string array, and how many Pin
Peter_in_278021-Nov-11 16:33
professionalPeter_in_278021-Nov-11 16:33 
Questionto read a file into an array Pin
robin70019-Nov-11 22:41
robin70019-Nov-11 22:41 
AnswerRe: to read a file into an array Pin
Maximilien20-Nov-11 0:24
Maximilien20-Nov-11 0:24 
AnswerRe: to read a file into an array Pin
Niklas L20-Nov-11 10:06
Niklas L20-Nov-11 10:06 
Questionsocket prograaming doubt! Pin
robin70019-Nov-11 10:04
robin70019-Nov-11 10:04 
AnswerRe: socket prograaming doubt! Pin
Erudite_Eric19-Nov-11 10:30
Erudite_Eric19-Nov-11 10:30 
AnswerRe: socket prograaming doubt! Pin
Albert Holguin19-Nov-11 15:41
professionalAlbert Holguin19-Nov-11 15:41 
QuestionApplication is getting crashed at ShowWndow Pin
Amrit Agr19-Nov-11 3:21
Amrit Agr19-Nov-11 3:21 
AnswerRe: Application is getting crashed at ShowWndow Pin
Chris Losinger19-Nov-11 3:49
professionalChris Losinger19-Nov-11 3:49 
AnswerRe: Application is getting crashed at ShowWndow Pin
Chuck O'Toole19-Nov-11 5:43
Chuck O'Toole19-Nov-11 5:43 
QuestionWhat is differences between a background thread and a modeless dialog? Pin
Member 28839419-Nov-11 0:31
Member 28839419-Nov-11 0:31 
AnswerRe: What is differences between a background thread and a modeless dialog? Pin
Richard MacCutchan19-Nov-11 0:41
mveRichard MacCutchan19-Nov-11 0:41 
AnswerRe: What is differences between a background thread and a modeless dialog? Pin
Albert Holguin19-Nov-11 15:48
professionalAlbert Holguin19-Nov-11 15:48 
QuestionMDI application with CMFCVisualManager, can dialog have the themes? Pin
rahul.kulshreshtha18-Nov-11 23:20
rahul.kulshreshtha18-Nov-11 23:20 
QuestionSimplest way to start a MFC program from a MFC program Pin
Member 28839418-Nov-11 21:38
Member 28839418-Nov-11 21:38 
AnswerRe: Simplest way to start a MFC program from a MFC program Pin
Richard MacCutchan18-Nov-11 22:01
mveRichard MacCutchan18-Nov-11 22:01 
GeneralRe: Simplest way to start a MFC program from a MFC program Pin
Member 28839418-Nov-11 23:01
Member 28839418-Nov-11 23:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.