当前位置: 代码迷 >> 综合 >> HDOJ 1039 Easier Done Than Said?
  详细解决方案

HDOJ 1039 Easier Done Than Said?

热度:81   发布时间:2023-10-21 18:19:33.0

HDACM 1039


翻译。


import java.util.Scanner;public class Main{static char ch[] = { 'a', 'e', 'i', 'o', 'u' };public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {String str = sc.next();if ("end".equals(str)) {break;}boolean ans[] = new boolean[str.length()];boolean condition1 = false;boolean condition2 = true;boolean condition3 = true;for (int i = 0; i < str.length(); i++) {char c = str.charAt(i);if (isVowel(c)) {ans[i] = true;condition1 = true;}if (i > 0) {char c2 = str.charAt(i - 1);if (c != 'e' && c != 'o' && c2 == c) {condition3 = false;break;}}}if (!condition3) {System.out.println("<" + str + "> is not acceptable.");continue;}if (!condition1) {System.out.println("<" + str + "> is not acceptable.");continue;}int x = 0;int y = 0;for (int i = 0; i < ans.length; i++) {if (ans[i]) {y=0;x++;}else{x=0;y++;}if (x==3||y==3) {condition2 = false;break;}}if (!condition2) {System.out.println("<" + str + "> is not acceptable.");continue;}System.out.println("<" + str + "> is acceptable.");}sc.close();}public static boolean isVowel(char c) {for (int i = 0; i < ch.length; i++) {if (c == ch[i]) {return true;}}return false;}
}