-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondLab.java
More file actions
75 lines (70 loc) · 3.58 KB
/
SecondLab.java
File metadata and controls
75 lines (70 loc) · 3.58 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
64
65
66
67
68
69
70
71
72
73
74
75
// Вивести в алфавітному порядку для даного тексту приголосні літери, які входять тільки в одне слово.
// A, E, I, O, U, Y.
import java.util.HashMap; // for hash map
import java.util.LinkedList;
import java.util.Map; // for map
import java.util.ArrayList;
public class SecondLab{
private static Map<Character, Boolean> nonRepeatedLetters;
public static ArrayList<String> buildRightArray(String [] words){
ArrayList<String> rightStrings = new ArrayList<String>();
for (String word : words) {
if (!rightStrings.contains(word)) {
rightStrings.add(word);
}
}
System.out.println(rightStrings);
return rightStrings;
}
public static void printLetters(String[] words) {
nonRepeatedLetters = new HashMap<Character, Boolean>();
ArrayList<String> rightStrings = buildRightArray(words);
ArrayList<Character> repeatedLetters = new ArrayList<Character>();
for (char i = 'a'; i < 'z'; i++) {
if(i != 'a' && i != 'e' && i != 'i' && i != 'o' && i != 'u' && i != 'y') nonRepeatedLetters.put(i, false);
}
for (int i = 0; i < rightStrings.size(); i++) {
if(i < rightStrings.size() - 1){
for (int j = i + 1; j < rightStrings.size(); j++) {
for (int l = 0; l < rightStrings.get(i).length(); l++) {
if ((rightStrings.get(j).indexOf(rightStrings.get(i).charAt(l)) == -1) &&
nonRepeatedLetters.containsKey(rightStrings.get(i).charAt(l)) &&
!repeatedLetters.contains(rightStrings.get(i).charAt(l))){
nonRepeatedLetters.replace(rightStrings.get(i).charAt(l), true);
//System.out.println("Letter " + rightStrings.get(i).charAt(l) + " isn't in word " + rightStrings.get(j));
}
else {
repeatedLetters.add(rightStrings.get(i).charAt(l));
nonRepeatedLetters.replace(rightStrings.get(i).charAt(l), false);
}
}
}
}
else{
for (int j = i - 1; j > 0; j--) {
for (int l = 0; l < rightStrings.get(i).length(); l++) {
if ((rightStrings.get(j).indexOf(rightStrings.get(i).charAt(l)) == -1 ) &&
nonRepeatedLetters.containsKey(rightStrings.get(i).charAt(l)) &&
!repeatedLetters.contains(rightStrings.get(i).charAt(l))){
nonRepeatedLetters.replace(rightStrings.get(i).charAt(l), true);
//System.out.println("Letter " + rightStrings.get(i).charAt(l) + " isn't in word " + rightStrings.get(j));
}
else{
repeatedLetters.add(rightStrings.get(i).charAt(l));
nonRepeatedLetters.replace(rightStrings.get(i).charAt(l), false);
}
}
}
}
}
for (Map.Entry<Character, Boolean> entry : nonRepeatedLetters.entrySet()){
if(entry.getValue() == true) System.out.print(entry.getKey() + " ");
}
}
public static void main(String[] args) {
String str = System.console().readLine();
str = str.toLowerCase();
String[] words = str.split("[ ,.]");
printLetters(words);
}
}