博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1039 Easier Done Than Said?
阅读量:5901 次
发布时间:2019-06-19

本文共 3598 字,大约阅读时间需要 11 分钟。

Easier Done Than Said?

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 14657 Accepted Submission(s): 7107

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

u

tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end

Sample Output

<u> 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.



Accepted Code

// Author : Weihao Long// Created : 2017/12/18#include "stdio.h"#include "string.h"int main() {    char word[25];    while (gets(word) != NULL) {        if (!strcmp(word, "end"))            break;        int flag = 0;        for (int i = 0; word[i] != '\0'; i++)            if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u') {                flag = 1;                break;            }        if (!flag) {            printf("<%s> is not acceptable.\n", word);            continue;        }        for (int i = 0; word[i + 1] != '\0'; i++) {            if (word[i] == word[i + 1] && (word[i] != 'e'&&word[i] != 'o')) {                flag = 0;                break;            }        }        if (!flag) {            printf("<%s> is not acceptable.\n", word);            continue;        }        char tmp[25];        strcpy(tmp, word);        for (int i = 0; word[i] != '\0'; i++)            if (tmp[i] == 'a' || tmp[i] == 'e' || tmp[i] == 'i' || tmp[i] == 'o' || tmp[i] == 'u')                tmp[i] = '0';            else                tmp[i] = '1';        for (int i = 0; tmp[i + 2] != '\0'; i++) {            if (tmp[i] == tmp[i + 1] && tmp[i + 1] == tmp[i + 2]) {                flag = 0;                break;            }        }        if (!flag)            printf("<%s> is not acceptable.\n", word);        else            printf("<%s> is acceptable.\n", word);    }    return 0;}

Notes

题意:

给一串密码,让你判断是否符合题目规定。
1.至少一个元音字母。
2.不能有三个连续的元音或辅音字母。
3.相邻两个字母不能相同,但“ee”和“oo”除外。

算法:

第一步:先扫一遍密码检查元音字母。
第二步:再扫一遍密码检查相邻字母是否相同。
第三步:开一个临时数组,把密码拷贝进来,但是元音变为数字“0”,辅音变为数字“1”。
第四步:扫一遍临时数组,检查连续三个是否同为元音“0”或辅音“1”。

转载地址:http://siesx.baihongyu.com/

你可能感兴趣的文章
Spring MVC中前后台数据传输小结
查看>>
Android详细的对话框AlertDialog.Builder使用方法
查看>>
2594 解药还是毒药
查看>>
Spring中使用@Profile指定不同的环境
查看>>
《精进:如何成为一个很厉害的人》读书笔记(转载)
查看>>
linux下修改/etc/profile文件
查看>>
cropper实现图片剪切上传
查看>>
谈谈java的BlockingQueue
查看>>
java 读excel xlsx
查看>>
20165313 我期望的师生关系
查看>>
CentOS7+CDH5.14.0安装CDH错误排查: HiveServer2 该角色的进程已退出。该角色的预期状态为已启动...
查看>>
GCC
查看>>
The Oregon Trail 俄勒冈之旅
查看>>
Excel VBA连接MySql 数据库获取数据
查看>>
php 的命名空间 看鸟哥后的随笔
查看>>
svn提交问题
查看>>
centos上的grub文件修改
查看>>
java 字节流输入输出
查看>>
小行星群 网络流 二分图
查看>>
微信小程序 组件 Demo
查看>>