Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
top5words
//Title of this code #include <iostream> #include <string> #include <vector> #include <map> #include <algorithm> using namespace std; bool comp(pair<string, int> a, pair<string, int> b) { return (a.second > b.second); } void printTop(vector<string>& t) { map<string, int> m; auto it = t.begin(); while (it != t.end()) { if (m.find(*it) == m.end()) m[*it] = 1; else ++m[*it]; ++it; } vector<pair<string, int>> vec(m.begin(), m.end()); sort(vec.begin(), vec.end(), comp); for (auto it = vec.begin(); it != vec.end(); ++it) cout << it->first << " - " << it->second << endl; } int main() { vector<string> t; t.push_back("hello"); t.push_back("bello"); t.push_back("mello"); t.push_back("jello"); t.push_back("hello"); t.push_back("llo"); t.push_back("llo"); t.push_back("ello"); t.push_back("ello"); t.push_back("hello"); printTop(t); }
run
|
edit
|
history
|
help
0
GCC compiler bug (should output 0 1)
ADAKOHL - hpclearn
xyz
pangram
Speed
basic TREAP
Median of row wise sorted matrix
vector fr
lab17feb22x4B.cpp
Kadane's Algorithm