Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3355550

Browse files
authored
Create 05 print string in lexicographical order.cpp
1 parent eff038d commit 3355550

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
/*given N string, print unique sting
6+
in Lexicpgraphical order with their frequency
7+
8+
*/
9+
10+
// map uses red black self balencing tree in backend and it always stored keys in sorted manner
11+
int main ()
12+
{
13+
map<string , int >m; // key as string and value as integer
14+
int n;
15+
cin>>n;
16+
for (int i=0;i<n;++i)
17+
{
18+
string s;
19+
cin>>s;
20+
/*m[s]=m[s]+1; or we can write m[s]++ both are same */
21+
m[s]++;
22+
}
23+
for (auto pr : m)
24+
{
25+
cout <<pr.first<<" "<< pr.second <<" " <<endl;
26+
}
27+
28+
}
29+
//

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /