-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcman.java
More file actions
49 lines (37 loc) · 1.13 KB
/
cman.java
File metadata and controls
49 lines (37 loc) · 1.13 KB
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
import java.util.Scanner;
public class Anticman {
public static String sortstr(String mystr)
{
String mystr2=mystr;
for (int i =1;i<mystr2.length();i=i+1){
for (int j = 0; j<i;j=j+1 ){
if (mystr2.charAt(i)<=mystr2.charAt(j)){
mystr2=mystr2.substring(0,j)+ mystr2.charAt(i)+mystr2.substring(j,i)+mystr2.substring(i+1);
}
}
}
return mystr2;
}
public static void anti(){
Scanner t = new Scanner(System.in);
int num = t.nextInt();
t.nextLine();
for (int i =0; i<num;i++){
String str3="";
String str1= t.nextLine();
String str2 = t.nextLine();
int l = str1.length();
for (int j =0 ; j<l ; j=j+1){
char x = str1.charAt(j);
if (str2.indexOf(x)!= -1){
str3 = str3 + x;
int y = str2.indexOf(x);
str2= str2.substring(0,y) + str2.substring(y+1);}
}
str3 = sortstr(str3);
System.out.println(str3);
}
}
public static void main(String[] args){
anti();}
}