hdu 1039 - Easier Done Than Said?

题目:给你一个小写字符串,判断是否安全,安全规则如下:

1.包含元音字母;2.相邻3个元素不能都是元音或辅音;3.连续2个字母相同之能是o或e。

分析:简单题。直接模拟即可。

说明:今天有点累╮(╯▽╰)╭,要学的东西好多( ⊙ o ⊙ )啊!

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int f(char c)
{
	return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}

char buf[32];

int main()
{
	while (gets(buf) && strcmp(buf, "end")) {
		int flag = 0;
		for (int i = 0 ; buf[i] ; ++ i)
			if (f(buf[i]))
				flag = 1;
		for (int i = 2 ; buf[i] ; ++ i) {
			if (f(buf[i])&&f(buf[i-1])&&f(buf[i-2]))
				flag = 0;
			if (!f(buf[i])&&!f(buf[i-1])&&!f(buf[i-2]))
				flag = 0;
		}
		for (int i = 1 ; buf[i] ; ++ i)
			if (buf[i] == buf[i-1] && buf[i] != 'e' && buf[i] != 'o')
				flag = 0;
		if (flag) printf("<%s> is acceptable.\n",buf);
		else printf("<%s> is not acceptable.\n",buf);
	}
    return 0;
}
时间: 2024-10-21 19:00:36

hdu 1039 - Easier Done Than Said?的相关文章

HDU 1039[Easier Done Than Said?] 字符串处理

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1039 题目大意:给一个字符串,看是否符合密码的要求. 规则:1.至少有1个元音字母.2.不能有3个连续的元音字母或辅音字母3.不能有相同的字母连续出现(除了ee,oo) 关键思想:耐心地处理字符串 代码如下: //可优化 #include <iostream> #include <algorithm> #include <string.h> using namespace

HDU ACM 1039 Easier Done Than Said? 水题

分析:判断密码是否安全. 三个条件:至少一个元音字母,连续三个字母不能同时为元音或辅音,连续两个字母不能相同,但"ee"和"oo"除外. #include<iostream> using namespace std; bool isyuan(char c) { return c=='a' || c=='e' || c=='i' || c=='o' || c=='u'; } bool judge(char a[]) { int i,l; l=strlen(

字符串 HDU 1039

规则: 1.必须至少包含一个元音字母.a e i o u 2.不能包含三个连续元音或者连续辅音字母. 3.不能包含两个连续字母,除了'ee'和'oo'. PS:字母个数(1<= N <=20). #define _CRT_SECURE_NO_DEPRECATE #include <stdio.h> #include <stdlib.h> #include <string.h> int is_vowel(char strIn) { if(strIn == 'a

HDU 1039(字符串判断 **)

题意是检查一个字符串是否满足三个条件: 一.至少有一个元音字母.二.不能出现三个连续的元音或三个连续的辅音.三.除了 ee 和 oo 外不能出现两个连续相同字母. 若三个条件都能满足,该字符串满足条件,有一个条件不满足则该字符串不满足条件. 但是这道题的数据......一定有元音字母,长度一定不少于 3.省去很多麻烦...... 代码如下: 1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int len;

DP题目

//HDU 4001 To Miss Our Children Time HDU 4433 locker HDU 4362 Dragon Ball[] HDU 3602 2012[] HDU 4385 Moving Bricks[] HLG 1067 QQ Farm[] HDU 4293 Groups HDU 3920 Clear All of Them I[] HDU 3466 Proud Merchants[] POJ 2923 Relocation[] HDU 3660 Alice and

HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following method: 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only c

Easier Done Than Said? 【杭电-1039】

/* Easier Done Than Said? Problem DescriptionPassword 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 xv

Easier Done Than Said? 【杭电-1039】 附题

/* Easier Done Than Said? Problem DescriptionPassword 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 xv

http://acm.hdu.edu.cn/showproblem.php?pid=1039(水~)

判读条件 1:有元音字母 2:不能三个连续元音或辅音 3.不能连续两个相同的字母,除非ee或oo 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<string> 5 using namespace std; 6 char word[30]; 7 bool panyuan(int id){ 8 if(word[id]=='a'||word[id]=='e'||wor