-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefix-removals.java
41 lines (29 loc) · 926 Bytes
/
prefix-removals.java
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
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class NewProg {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T>0){
T--;
int check = -1;
StringBuilder str = new StringBuilder(sc.next());
outer:
for (int i = 0; i<str.length()-1; i++){
for (int j = i+1; j<str.length(); j++){
if (str.charAt(i) == str.charAt(j)){
str.setCharAt(i, '0');
check++;
break;
}
}
if (check !=i){
break outer;
}
}
String strNew = str.toString().replaceAll("[0]+", "");
System.out.println(strNew);
}
}
}