Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
top5words
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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); }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1.35 sec, absolute running time: 0.14 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 1.5 sec
fork mode
|
history
|
discussion
hello - 3 ello - 2 llo - 2 bello - 1 jello - 1 mello - 1