-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforce988B.java
More file actions
63 lines (41 loc) · 1.28 KB
/
Copy pathCodeforce988B.java
File metadata and controls
63 lines (41 loc) · 1.28 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Codeforce988B {
public static void main(String[] args)throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(input.readLine());
Pair [] words = new Pair[n];
for (int i = 0; i < n; i++) {
words[i] = new Pair(input.readLine());
}
if (n == 1){
System.out.println("YES");
System.out.println(words[0].word);
return;
}
Arrays.sort(words);
for (int i = 0; i < n - 1; i++) {
if (!words[i + 1].word.contains(words[i].word)){
System.out.println("NO");
return;
}
}
System.out.println("YES");
StringBuilder out = new StringBuilder();
for (Pair word : words) {
out.append(word.word).append("\n");
}
System.out.println(out.toString().trim());
}
}
class Pair implements Comparable<Pair>{
String word;
public Pair(String word) {
this.word = word;
}
@Override
public int compareTo(Pair pair) {
return this.word.length() - pair.word.length();
}
}