HDOJ 1039 Easier Done Than Said?

来源:互联网 发布:淘宝宝贝首图优化 编辑:程序博客网 时间:2024/06/05 17:00

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;    }}