/*
Given N strings, print the unique strings in lexiographical order with their frequenices
1<=N<=10^5
1<=|S|<=100
*/

#include <iostream>
#include<map>
using namespace std;
int main() {
    map<string,int> m;   //string--> to store input strings and int--> to store frequenices of string 
    int n; cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        m[s]++;   //here string will store in the map with initial frequeny 1 if there is any duplicate the value will get increment by 1
    }
    for(auto i: m){
        cout<<i.first<<" "<<i.second<<"\n";
    }
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: