HDU-1039 Easier Done Than Said?(字符串简单题)

版权声明:IT交流QQ群328880248,欢迎大家来一起学习一起交流~本篇文章未经同意请勿转载! https://blog.csdn.net/m0_38072683/article/details/87452972

Easier Done Than Said?

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)

Total Submission(s) : 32   Accepted Submission(s) : 9

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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.

思路

三个条件:

这道题简单,就不多说了,直接看代码就行了。

代码

#include<cstdio>
#include<cstring>
using namespace std;

const int maxn = 22;
char a[maxn];

int main() {
	while (~scanf("%s",a) && strcmp(a, "end")) {
		int len = strlen(a); 
		
		//元音连续个数 
		int sum_a = 0;
		//辅音连续个数 
		int sum_b = 0;
		//前一个字母 
		char pre_c = a[0];
		//是否不合法 
		bool flag = false;
		//是否有元音 
		bool hasVowel = true;
		
		for (int i = 0; i < len; ++i) {
			if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') {
				// 是否有元音 
				if (hasVowel) hasVowel = false;
				//如果辅音已经连续3个,那么break,不合法
				//否则 将sum_b清0 
				if (sum_b == 3) {
					flag = true;
					break;
				} else {
					sum_b = 0;
				}
				sum_a ++;
			} else {
				//如果元音已经连续3个,那么break,不合法
				//否则 将sum_a清0
				if (sum_a == 3) {
					flag = true;
					break;
				} else {
					sum_a = 0;
				}
				sum_b ++;
			}
			// 判断前后两个字母是否相同(除oo、ee) 
			if (pre_c == a[i] && a[i] != 'o' && a[i] != 'e' && i != 0) {
				flag = true;
				break;
			}
			pre_c = a[i];
		}
		
		// 针对这种情况 whooo  
		if (sum_a == 3 || sum_b == 3){
			flag = true;
		}
		
		if (flag || hasVowel) {
			printf("<%s> is not acceptable.\n", a);
		} else {
			printf("<%s> is acceptable.\n", a);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_38072683/article/details/87452972