How to get appear times between 2 and 5 in a vector?
-
extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7
I want to get the number list included 5, 6 -
extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7
I want to get the number list included 5, 6Can you rephrase your question? Saurabh
-
extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7
I want to get the number list included 5, 6:confused:
Regards, Vijay.
-
extern vector v; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7
I want to get the number list included 5, 6This should work
extern vector vData; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7 // loop count occurance of all items using a map // std::map<int, int> mapCount; for(std::vector<int>::const_iterator it = vData.begin(); it != vData.end(); it++) { mapCount[*it]++; } // check the map and save the data you need // std::vector<int> vFound; for(std::map<int, int>::const_iterator itmap = mapCount.begin(); itmap != mapCount.end(); itmap++) { if(itmap->second >= 2 && itmap->second <= 5) { vFound.push_back(itmap->first); } }
codito ergo sum
modified on Thursday, April 24, 2008 1:24 PM
-
This should work
extern vector vData; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7 // loop count occurance of all items using a map // std::map<int, int> mapCount; for(std::vector<int>::const_iterator it = vData.begin(); it != vData.end(); it++) { mapCount[*it]++; } // check the map and save the data you need // std::vector<int> vFound; for(std::map<int, int>::const_iterator itmap = mapCount.begin(); itmap != mapCount.end(); itmap++) { if(itmap->second >= 2 && itmap->second <= 5) { vFound.push_back(itmap->first); } }
codito ergo sum
modified on Thursday, April 24, 2008 1:24 PM
Wow, you must be genius. How did you figured that one :-D -Saurabh
-
Wow, you must be genius. How did you figured that one :-D -Saurabh
-
This should work
extern vector vData; // 1,2,3,4,5,5,5,6,6,7,7,7,7,7,7 // loop count occurance of all items using a map // std::map<int, int> mapCount; for(std::vector<int>::const_iterator it = vData.begin(); it != vData.end(); it++) { mapCount[*it]++; } // check the map and save the data you need // std::vector<int> vFound; for(std::map<int, int>::const_iterator itmap = mapCount.begin(); itmap != mapCount.end(); itmap++) { if(itmap->second >= 2 && itmap->second <= 5) { vFound.push_back(itmap->first); } }
codito ergo sum
modified on Thursday, April 24, 2008 1:24 PM
Thank you! your code is I need.