This repository was archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoTConverter.java
More file actions
46 lines (43 loc) · 1.49 KB
/
StoTConverter.java
File metadata and controls
46 lines (43 loc) · 1.49 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
import java.util.*;
import java.util.stream.Collectors;
public class StoTConverter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();sc.nextLine();
for(int run = 0; run < N; run++) {
String s = sc.nextLine(),t = sc.nextLine(),p = sc.nextLine();
ArrayList<Character> needed = new ArrayList<Character>();
System.out.println("s:"+s+"\n"+"t:"+t+"\n"+"p:"+p);
try {
int min = Integer.min(s.length(),t.length());
for(int i = 0; i < min; i ++) {
if(!(s.charAt(i) == t.charAt(i))) {
throw new Exception("SOLUTION REQUIRES REORDER");
}
}
for(int i =0 ; i < t.length(); i ++) {
//System.out.println("add "+i);
needed.add(t.charAt(i));
}
System.out.println("End Result: "+needed);
for(int i =0 ; i < s.length(); i ++) {
needed.remove(needed.indexOf(s.charAt(i)));
}
System.out.println("Letters needed: "+needed);
List<Character> chars = p.chars() // IntStream
.mapToObj(e -> (char)e) // Stream<Character>
.collect(Collectors.toList());
//System.out.println("Letters to find: "+needed);
System.out.println("Letters to be used before: "+chars);
for(char c: needed) {
//chars.remove(Character.valueOf(c));
chars.remove(chars.indexOf(c));
}
System.out.println("Letters to be used after: "+chars);
System.out.println("YES");
}catch(Exception e) {
System.out.println("NO "+e.getLocalizedMessage());
}
}
}
}