https://www.acmicpc.net/problem/4659
flag
또는 count
변수로 체크boolean
int
char
char
배열// Java 예시 코드
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String input = br.readLine();
if (input.equals("end"))
break;
boolean isAccept = true;
boolean hasVowel = false;
int vowelCount = 0;
int nonVowelCount = 0;
char lastChar = 0;
for (int i=0; i<input.length(); i++) {
char c = input.charAt(i);
// 모음 포함 여부
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
hasVowel = true;
vowelCount ++;
nonVowelCount = 0;
} else {
nonVowelCount ++;
vowelCount = 0;
}
// 같은 문자 3개 연속 오면 안 됨
if (nonVowelCount >= 3 || vowelCount >= 3) {
isAccept = false;
break; }
// 같은 문자 연속 오면 안 됨(e,o 제외)
if (i != 0 && c == lastChar) {
if (!(c == 'e' || c == 'o')) {
isAccept = false;
break;
}
}
lastChar = c;
}
if (!hasVowel) {
isAccept = false;
}
if (isAccept) {
System.out.println("<" + input + "> is acceptable.");
} else {
System.out.println("<" + input + "> is not acceptable.");
}
}
}
}
count
관리가 복잡했다. (모음이 연속되면 자음 카운트를 초기화 해야하는 등)