Did you mean...

Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.

Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.

For example:

the following words have typos: “hellno”, “hackcerrs” and “backtothefutttture”;
the following words don’t have typos: “helllllooooo”, “tobeornottobe” and “oooooo”.
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.

Implement this feature of Beroffice editor. Consider the following letters as the only vowels: ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’. All the other letters are consonants in this problem.

Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.

Output
Print the given word without any changes if there are no typos.

If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn’t have any typos. If there are multiple solutions, print any of them.

Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f

写这个题解主要是想给自己敲敲警钟…

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char a[100010];
bool yuany(int h)   //判断是否为元音字母
{
	if(h=='a'||h=='e'||h=='i'||h=='o'||h=='u')
	{
		return true;
	}
	return false;
}
int main()
{
	while(scanf("%s",a)!=EOF) 
	{
		int x=0;    //x是用来记录辅音字母的个数的,还没有开始遍历时,个数为0
		for(int i=0; a[i]!='\0'; i++)
		{
			if(yuany(a[i])) x=0;   //一遇到元音就可以重新开始计数(题目要求连续的不同的辅音不能超过三个。
			else
			{
				x++;   //else就是辅音的情况,数量++;
				if(x>2&&((a[i]!=a[i-1])||(a[i-1]!=a[i-2])))   //有三个连续的不同的辅音就要开始动手了
				{
					printf(" ");
					x=1;  //把第三个辅音放在下一块的第一个
				}
			}
			printf("%c",a[i]);
		}
		printf("\n");
	}
	return 0;
}

发布了8 篇原创文章 · 获赞 0 · 访问量 166

猜你喜欢

转载自blog.csdn.net/Erin_jwx/article/details/104030409