forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1450A - Avoid Trygub.cpp
74 lines (57 loc) · 2.16 KB
/
1450A - Avoid Trygub.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
A string b is a subsequence of a string a if b can be obtained from a by deletion of several (possibly, zero or all) characters. For example, "xy" is a subsequence of "xzyw" and "xy", but not "yx".
You are given a string a. Your task is to reorder the characters of a so that "trygub" is not a subsequence of the resulting string.
In other words, you should find a string b which is a permutation of symbols of the string a and "trygub" is not a subsequence of b.
We have a truly marvelous proof that any string can be arranged not to contain "trygub" as a subsequence, but this problem statement is too short to contain it.
Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤200) — the length of a.
The next line contains the string a of length n, consisting of lowercase English letters.
Output
For each test case, output a string b of length n which is a permutation of characters of the string a, and such that "trygub" is not a subsequence of it.
If there exist multiple possible strings b, you can print any.
Example
inputCopy
3
11
antontrygub
15
bestcoordinator
19
trywatchinggurabruh
outputCopy
bugyrtnotna
bestcoordinator
bruhtrywatchinggura
Note
In the first test case, "bugyrtnotna" does not contain "trygub" as a subsequence. It does contain the letters of "trygub", but not in the correct order, so it is not a subsequence.
In the second test case, we did not change the order of characters because it is not needed.
In the third test case, "bruhtrywatchinggura" does contain "trygu" as a subsequence, but not "trygub".
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
int cntb=0;
for(auto &ch: s)
if(ch=='b') cntb++;
string res="";
if(cntb==0) cout<<s<<endl;
else {
res.append(cntb, 'b');
for(auto &ch: s){
if(ch!='b') res+=ch;
}
cout<<res<<endl;
}
}
return 0;
}