-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaptukhacnhau.java
35 lines (29 loc) · 1002 Bytes
/
taptukhacnhau.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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
class WordSet {
TreeSet<String> set;
WordSet(String s) {
set = new TreeSet<>();
set.addAll(Arrays.asList(s.trim().toLowerCase().split("\\s+")));
}
String union(WordSet other) {
TreeSet<String> union = (TreeSet<String>) set.clone();
union.addAll(other.set);
return String.join(" ", union);
}
String intersection(WordSet other) {
TreeSet<String> intersection = (TreeSet<String>) set.clone();
intersection.retainAll(other.set);
return String.join(" ", intersection);
}
}
public class Taptukhacnhau {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new File("VANBAN.in"));
WordSet s1 = new WordSet(in.nextLine());
WordSet s2 = new WordSet(in.nextLine());
System.out.println(s1.union(s2));
System.out.println(s1.intersection(s2));
}
}