-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp4659.java
More file actions
61 lines (55 loc) · 1.97 KB
/
p4659.java
File metadata and controls
61 lines (55 loc) · 1.97 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
import java.io.*;
import java.util.*;
public class p4659 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
while (true) {
String input = br.readLine();
if (input.equals("end")) break;
sb.append("<").append(input).append("> is ");
if (!isHighQuality(input)) {
sb.append("not ");
}
sb.append("acceptable.").append("\n");
}
System.out.println(sb.toString());
}
static boolean isHighQuality(String s) {
char[] cArr = s.toCharArray();
List<Character> cList = new ArrayList<>();
for (int i = 0; i < cArr.length; i++) {
cList.add(cArr[i]);
}
// 모음을 포함하는지
if (!haveMo(cList)) return false;
// 자음 혹은 모음 연속 3개가 오는지
for (int i = 2; i < cArr.length; i++) {
// 모음일 때
if (isMo(cArr[i])) {
if (isMo(cArr[i - 1]) && isMo(cArr[i - 2])) {
return false;
}
} else {
if (!isMo(cArr[i - 1]) && !isMo(cArr[i - 2])) {
return false;
}
}
}
// ee, oo 제외한 연속 2개가 오는지
for (int i = 1; i < cArr.length; i++) {
if (cArr[i] == cArr[i - 1]) {
if (cArr[i] != 'e' && cArr[i] != 'o') {
return false;
}
}
}
return true;
}
static boolean haveMo(List<Character> cList) {
return (cList.contains('a') || cList.contains('e') || cList.contains('i') || cList.contains('o') || cList.contains('u'));
}
static boolean isMo(Character c) {
return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}
}