Playground
#include <iostream> #include <map> #include <string> using namespace std; int main() { map<string, int> occurrences; int N; cin >> N; for(int i=0; i<N; i++) { string name; cin >> name; occurrences[name] = occurrences[name] + 1; cout << name << " appears for the " << occurrences[name] << " time." << endl; } cout << "There are a total of " << occurrences.size() << " different names read." << endl; return 0; }
Input data
Program output
5 emil marko marko emil emil
Execute
Language: ????????? | Memory: ???? KB | Time: ??? ms
Nothing has been executed, yet!