HDU-1039 Easier Done Than Said?

HDU-1039 Easier Done Than Said?

问题描述:

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.

输入说明:

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.

输出说明:

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

思路:

题意就是要我们去判断一串字符串是否能作为密码,题目给出三个条件:1.必须含有一个元音 2.不能有连续3个同样的字母出现 3 不能有连续两个相同字母出现(除了e和o),输入时注意最后有一个end作为输入结束的判断,输出时按照题目的要求进行操作。处理方式就是列举出所有不符合条件的情况。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int yuanyin(char s)
{
    
    
	if(s=='a'||s=='e'||s=='i'||s=='o'||s=='u')
		{
    
    
		    return 1;
		}
	return 0;
}
int main()
{
    
    
	char s[100],end[]="end";
	int i,count1,count2,f1,f2;//count1表示元音,count2表示辅音,f1表示该密码是否可行,f2表示密码中是否含有元音
	while(scanf("%s",s)!=EOF)
    {
    
    
		if(strcmp(s,end)==0)//判断输入是否结束
			break;
		count1=count2=f1=f2=0;
		for(i=0;i<strlen(s);i++)
        {
    
    
			if(yuanyin(s[i]))
            {
    
    
				f2=1;//规则1
				count1++;
				count2=0;
				if(count1==2 && s[i]==s[i-1] && s[i]!='e' && s[i]!='o')//规则3
                {
    
    
                    f1=1;
                }
				if(count1==3)//规则2
				{
    
    
                        f1=1;
				}
			}
			else {
    
    
				count2++;
				count1=0;
				if(count2==2&&s[i]==s[i-1])//规则3
				{
    
    
                        f1=1;
				}
   				 if(count2==3)//规则2
                {
    
    
                    f1=/**/1;
                }
			}
			if(f1)     break;
		}
		if(f1 || f2==0)printf("<%s> is not acceptable.\n",s);
		else printf("<%s> is acceptable.\n",s);
	}
	return 0;
 }


猜你喜欢

转载自blog.csdn.net/m0_51727949/article/details/114433827