problem no 33:string problem:sort the string in the decreasing order.

 QUESTION:

 

Given a string S containing only lower case alphabets, the task is to sort it in lexigraphically-descending order.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a string S.

Output:
For each test case, in a new line, print the sorted string.

Constraints:
1 <= T <= 100
1 <= |S| <= 105

Example:
Input:
2
geeks
for
Output:
skgee
rof

 

ANSWER:

#include <iostream>
#include<cstring>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        
         sort(s.begin(), s.end(), greater<char>());
        cout<<s<<"\n";
        
        
   }
    return 0;
}


Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

Problem no 16: count the number of squares below N.