-
Notifications
You must be signed in to change notification settings - Fork 19
/
dyslectionary.java
60 lines (46 loc) · 1.34 KB
/
dyslectionary.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
import java.util.*;
import java.io.*;
public class dyslectionary {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
boolean end = false;
while (scan.hasNext())
{
ArrayList<String> words = new ArrayList<>();
int max = 0;
while (true)
{
String word = scan.nextLine();
if (!scan.hasNext())
end = true;
if (word.isEmpty())
break;
max = word.length() > max ? word.length() : max;
words.add(word);
if (end)
break;
}
for (int i = 0; i < words.size(); i++)
{
String word = words.get(i);
int spaces = max - word.length();
for (int z = 0; z < spaces; z++)
word = " " + word;
words.set(i , word);
}
Collections.sort(words , new Comparator<String>() {
public int compare(String str1 , String str2) {
for (int i = str1.length() - 1; i >= 0; i--)
if (str1.charAt(i) != str2.charAt(i))
return str1.charAt(i) - str2.charAt(i);
return 0;
}
});
for (String word : words)
System.out.println(word);
if (!end)
System.out.println();
}
scan.close();
}
}