您的位置:首页 > 其它

Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】

2017-09-18 17:39 681 查看

C. Did you mean...

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

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


题目链接:http://codeforces.com/contest/861/problem/C

分析:直接看代码吧,代码中给出了详细注释!

下面给出AC代码:

#include <bits/stdc++.h>
using namespace std;
const int N=3e3;
int n;
int a[N+10],is[400];
char s[N+10];
int main(void)
{
is['a']=is['e']=is['i']=is['o']=is['u']=1;
cin>>(s+1);
n=strlen(s+1);
int cnt=0;
for(int i=1;i<=n;i++)
{
if(!is[s[i]])
{
cnt++;
if(cnt>=3)
{
bool ok=true;
int j=max(1,i-2);
for(int k=j;k<=i-1;k++)//前面的3个都和它一样吗
if(s[k]!=s[i])
ok=false;
if(ok)//如果是的话
{
cout<<s[i];
int k=i;
while(k+1<=n&&s[k+1]==s[i])//往后一直找和它一样的
{
k++;
cout<<s[k];
}
cnt=2;
i=k;//cnt变成2了,指向下一个。
}
else//不是的话。只能分割了。
{
cout<<' '<<s[i];
cnt=1;
}
}
else
cout<<s[i];//没3个
}
else//是元音直接输出
{
cout<<s[i];
cnt=0;
}
}
//连续出现
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐