杭电ACM1039——Easier Done Than Said?

这一题,简单的字符串处理。只是题目的要求比较麻烦。

题目的大概意思是:给你一段字符串,判断是否可以被接受。

判断的条件为:

1.存在一个元音。(元音有a,e,i,o,u)

2.不能有连续的三个元音或者连续的三个非元音。

3.不能有连续的两个相同字符除了e和o可以之外

有了这些条件,就很容易了。

下面的是一次AC的代码,有详细的注释:

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

int main()
{
	char str[25];
	int tag[25], flag[25];           //tag数组是来判断是否有三个元音连续和非元音连续,flag数组判是否有两个相同字符连续
	while(cin >> str)
	{
		if(strcmp(str, "end") == 0)   //结束标记
			break;
		int len = strlen(str);
		memset(tag, 0, sizeof(tag));   //初始化两个数组
		memset(flag, 0, sizeof(flag));
		for(int i = 0; i < len; i++)
		{
			if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
			{
				tag[i] = 1;                   //是元音,标记该位置为1;
				if(i > 0 && (str[i - 1] == 'a' || str[i - 1] == 'e' || str[i - 1] == 'i'
					|| str[i - 1] == 'o' || str[i - 1] == 'u'))  //如果它的上一个位置为1,相加起来
				{                                                //最后判断是否有3出现,就可以知道是否有3个元音连续
					tag[i] += tag[i - 1];
				}
			}
			else                               //同理,非元音也是,只是是判-3而已
			{
				tag[i] = -1;
				if(i > 0 && !(str[i - 1] == 'a' || str[i - 1] == 'e' || str[i - 1] == 'i'
					|| str[i - 1] == 'o' || str[i - 1] == 'u'))
				{
					tag[i] += tag[i - 1];
				}
			}
			if(i > 0 && str[i] == str[i - 1] && (str[i] != 'e' && str[i] != 'o')) //判是否有两个相同的连续
				flag[i] = 1;
		}
		int a, b, c, d;
		a = b = c = d = 0;
		for(int j = 0; j < len; j++)
		{
			if(tag[j] == 1)           //判是否存在元音
				a = 1;
			if(tag[j] == 3)           //判是否存在三个元音连续
				b = 1;
			if(tag[j] == -3)          //判是否存在三个非元音连续
				c = 1;
			if(flag[j] == 1)          //判是否存在两个相同的字符连续,除e和o的
				d = 1;
		}
		if(a == 1 && b == 0 && c == 0 && d == 0)
			cout << '<' << str << '>' << " is acceptable." << endl;
		else
			cout << '<' << str << '>' << " is not acceptable." << endl;
	}
	return 0;
}
时间: 2024-12-09 18:11:29

杭电ACM1039——Easier Done Than Said?的相关文章

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

杭电1212--Big Number

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5961    Accepted Submission(s): 4167 Problem Description As we know, Big Number is always troublesome. But it's really important in our

Big Number------HDOJ杭电1212(大数运算)

Problem Description As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B. To make the problem easier, I promise that B will be smaller than 100000. Is it t

杭电 HDU ACM 1212 Big Number

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5606    Accepted Submission(s): 3903 Problem Description As we know, Big Number is always troublesome. But it's really important in ou

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不