杭电 1039【判断密码】

Easier Done Than Said?

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.
/*
*对所输入的密码进行判断:

它必须包含至少一个元音(a,e,i,o,u)
它不能包含三个连续的元音或连续三个辅音。(就是辅音或元音不能出现连续的三个的集合,比不能出现连续的三个字符判断面更广)
它不能包含两个连续出现相同的信,除了“ee”或“oo”。
*
*/
#include<iostream>
using namespace std;
int main()
{
	//b作为标识符记录所输入的密码是否符合要求,b=1时表示符合要求,否则不符合要求
    int n,m,i,j,b;
	//按照题目要求输入的密码长度不超过20,字符串数组a中负责存放输入的密码数组
    char a[20];
	//通过while循环持续对输入的密码进行判断
    while(cin>>a)
    {
        m=0;j=0;b=0;
		//当输入的字符串为end退出命令时,退出(此题的测试用例中大概也没有以end开头的密码所以能成功)
        if(a[0]=='e'&&a[1]=='n'&&a[2]=='d')
        {break;}
		//通过strlen函数在n中获取到所输入的密码的长度
        n=strlen(a);
		//通过n以内的for循环对本次输入的密码进行判断
        for(i=0;i<n;i++)
        {
			//当密码中出现元音,满足其中一个条件。先预判为可接受,b=1,m负责记录元音的连续,j负责记录辅音的连续
            if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')
            {
                b=1;
                m++;
                j=0;
            }
			//当密码中出现的不是元音则,元音连续值记录器清零,辅音连续值记录器自增
            else
            {
                j++;
                m=0;
            }
			//按照题目要求除ee和oo外不能出现两个连续的字符,则对其进行判断
            if(i<n-1)
            {
				//如果此时的值为e或者o则出现两个连续的并不影响其可接受性
                if(a[i]=='e'||a[i]=='o')
                {b=1;}
				//但是如果此时目前的字符不是e也不是o并且此时出现两个连续的字符,则可判定这串密码是不符合要求的,b=0后退出循环
                else if(a[i]==a[i+1])
                {b=0;break;}
            }
			//如果在某一次的for循环的判断中已经连续出现了三个辅音或三个元音,则可判断为此密码不符合要求b=0后退出循环
            if(m>=3||j>=3)
            {b=0;break;}
        }
		//规范标识符b=1时,此密码是符合规范的,按照格式要求对符合规范的密码进行显示
        if(b==1)
        {
            cout<<"<"<<a<<"> is acceptable."<<endl;
        }
		//规范标识符b=0时,此密码是不符合规范的,按照格式要求对不符合规范的密码进行显示
        else
        {
            cout<<"<"<<a<<"> is not acceptable."<<endl;
        }
    }
    return 0;
}


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值