-
Notifications
You must be signed in to change notification settings - Fork 0
/
_11062.java
70 lines (59 loc) · 2.01 KB
/
_11062.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package io.github.tahanima.contestvolumes.volume110;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
/**
* @author tahanima
* @since 05/12/2021
* @see <a href="https://onlinejudge.org/external/110/11062.pdf">Problem Statement</a>
*/
public class _11062 {
public static ArrayList<String> getWordList(String line) {
ArrayList<String> answer = new ArrayList<>();
StringBuilder word = new StringBuilder();
for (Character ch : line.toCharArray()) {
if (Character.isLetter(ch) || ch == '-') {
word.append(ch);
} else {
if (word.length() > 0)
answer.add(word.toString().toLowerCase());
word = new StringBuilder();
}
}
if (word.length() > 0)
answer.add(word.toString().toLowerCase());
return answer;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
TreeSet<String> words = new TreeSet<>();
StringBuilder line = new StringBuilder();
boolean hasDash = false;
while (input.hasNextLine()) {
String current = input.nextLine().trim();
if (hasDash) {
if (current.endsWith("-")) {
line.append(current, 0, current.length() - 1);
} else {
line.append(current);
hasDash = false;
}
} else {
if (current.endsWith("-")) {
line.append(current, 0, current.length() - 1);
hasDash = true;
} else {
line.append(current);
}
}
if (!hasDash) {
ArrayList<String> wordList = getWordList(line.toString());
words.addAll(wordList);
line = new StringBuilder();
}
}
for (String word : words) {
System.out.println(word);
}
}
}