-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13417.java
More file actions
34 lines (28 loc) · 971 Bytes
/
13417.java
File metadata and controls
34 lines (28 loc) · 971 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
import java.io.*;
import java.util.*;
public class Main{
static String answer(String str){
char[] cards = str.toCharArray();
StringBuilder answer = new StringBuilder();
answer.append(cards[0]);
for(int i=1; i<cards.length; i++){
if(answer.charAt(0)<cards[i])
answer.append(cards[i]);
else
answer.insert(0,cards[i]);
}
return answer.toString();
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringTokenizer st;
StringBuilder sb = new StringBuilder();
for(int i=0; i<t; i++){
br.readLine();
String str = br.readLine().replaceAll(" ","");
sb.append(answer(str)).append(System.lineSeparator());
}
System.out.println(sb);
}
}