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): 7107Problem 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
tvptouibontreszoggaxwiinqeephouctuhendSample 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”。