Here is the given question: Given a string S you have to sort the characters of the string in lexicographically decreasing order. Note - Do not use the inbuilt sorting function.
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{
//write your code here
int t;
cin>>t;
while(t--)
{
int n,temp,min,i,j;
string s,text;
cin>>s;
n=s.length();
int arr[n];
for(int i=0;i<n;i++)
{
arr[i]=int(s[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]<arr[j])
{
temp =arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int l=0;l<n;l++)
{
text[l]=arr[l];
cout<<text[l];
}
cout<<endl;
}
return 0;
}
Input
1
algorithm
Output
tromlihga