杭电ACM OJ 1039 Easier Done Than Said? 水(但是很好玩的一道题,考察逻辑思维)

本文介绍了杭电ACM在线判题系统OJ中的一道题目1039 'Easier Done Than Said?',尽管被标记为水题,但这道题目因其有趣的逻辑思维考验而颇受欢迎。通过对题目的解析,读者可以体验到解题的乐趣并提升逻辑分析能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Easier Done Than Said?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14426    Accepted Submission(s): 6986


Problem Description
Password security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passwords are often insecure. Some sites use random computer-generated passwords (like xvtpzyo), but users have a hard time remembering them and sometimes leave them written on notes stuck to their computer. One potential solution is to generate "pronounceable" passwords that are relatively secure but still easy to remember.

FnordCom is developing such a password generator. You work in the quality control department, and it's your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules:

It must contain at least one vowel.

It cannot contain three consecutive vowels or three consecutive consonants.

It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.

(For the purposes of this problem, the vowels are 'a', 'e', 'i', 'o', and 'u'; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable.
 

Input
The input consists of one or more potential passwords, one per line, followed by a line containing only the word 'end' that signals the end of the file. Each password is at least one and at most twenty letters long and consists only of lowercase letters.
 

Output
For each password, output whether or not it is acceptable, using the precise format shown in the example.
 

Sample Input
a tv ptoui bontres zoggax wiinq eep houctuh end
 

Sample Output
<a> is acceptable. <tv> is not acceptable. <ptoui> is not acceptable. <bontres> is not acceptable. <zoggax> is not acceptable. <wiinq> is not acceptable. <eep> is acceptable.

<houctuh> is acceptable.

翻译:给你一个字符串作为密码。需要满足3个条件

1.至少包含一个元音(a e i o u) 2.不能包含3个连续的元音或者辅音 3.除了ee,oo外不能包含连续出现两个相同的字母

做法:

1.至少包含一个元音(a e i o u) 2.不能包含3个连续的元音或者辅音,设置一个yCount和fCount的变量来保存,优雅完美! 3.除了ee,oo外不能包含连续出现两个相同的字母,维护上一个变量进行比较,优雅完美!

代码:

package ACM1000_1099;

public class EasierDoneThanSaid1039 {
    // TODO: 2017/12/5 1.至少包含一个元音(a e i o u)
    // TODO: 2017/12/5 2.不能包含3个连续的元音或者辅音,当有元或辅来个变量保存个数
    // TODO: 2017/12/5 3.除了eeoo外不能包含连续出现两个相同的字母,也是一样,维护上一个

    void calculate() {
        char[][] a = {
                {'a'},
                {'t','v'},
                {'p','t','o','u','i'},
                {'b','o','n','t','r','e','s'},
                {'z','o','g','g','a','x'},
                {'w','i','i','n','q'},
                {'e','e','p'},
                {'h','o','u','c','t','u','h'},
                };

        int height = a.length;

        boolean haveAEIOU;

        int yCount;
        int fCount;

        char current;

        for (int i = 0; i < height; i ++) {
            haveAEIOU = false;

            yCount = 0;
            fCount = 0;

            current = '%';
            for (int j = 0; j < a[i].length; j ++) {
                //如果有元音 设为true
                if (a[i][j] == 'a' || a[i][j] == 'e' ||
                        a[i][j] == 'i' ||a[i][j] == 'o' ||
                        a[i][j] == 'u') {
                    haveAEIOU = true;

                    //fCount不为0代表你刚存的是辅音,而且没到3
                    if (fCount != 0) {
                        fCount = 0;
                    }
                    yCount ++;
                    if (yCount == 3) {
                        System.out.println("不能3个连续元音");
                        break;
                    }
                } else {
                    if (yCount != 0) {
                        yCount = 0;
                    }
                    fCount ++;
                    if (fCount == 3) {
                        System.out.println("不能3个连续辅音");
                        break;
                    }
                }

                //保存上一个字符
                if (a[i][j] == current && current != 'e' && current != 'o') {
                    System.out.println("不能2个连续一样且不是eeoo");
                    break;
                }
                current = a[i][j];

                if (j == a[i].length - 1) {
                    if (!haveAEIOU) {
                        System.out.println("不能没有元音");
                    } else {
                        System.out.println("符合条件");
                    }
                }
            }
        }
    }

    public static void main(final String[] args) throws Exception {
        EasierDoneThanSaid1039 e = new EasierDoneThanSaid1039();
        e.calculate();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值