-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSort String
More file actions
36 lines (35 loc) · 759 Bytes
/
Sort String
File metadata and controls
36 lines (35 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Given a string of lowercase characters from ‘a’ – ‘z’. We need to write a program to print the characters of this string in sorted order.
// Example:
// Input:
// 2
// bbccdefbbaa
// geeksforgeeks
// Output :
// aabbbbccdef
// eeeefggkkorss
#include<iostream>
#include<string>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int hash[27]={0};
string st;
cin>>st;
int len=st.length();
for(int i=0;i<len;i++)
hash[st[i]-96]++;
for(int i=0;i<27;i++)
if(hash[i]>0)
while(hash[i])
{
cout<<(char)(i+96);
hash[i]--;
}
cout<<endl;
}
return 0;
}