您的位置:首页 > 其它

Codeforces Round #434 (Div.2) - C - Did you mean...

2017-09-18 11:08 357 查看
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 3000letters.

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


题意:

1.有一个长度在1-3000的字符串

2.将所给串分为一个或多个合法串

合法串:串内不存在三个或三个以上的连续辅音字母,所有连续辅音字母均相同除外

3.辅音字母:除元音字母外的所有字母;元音字母:’a’,’e’,’i’,’o’,’u’

4.在分割时使用一个空格分割,要尽量少的分割。

题解:

从左到右遍历,在每个位置判断以下几点:

1.是否为辅音字母

(1).是

.下一字母是否为辅音字母(否则跳过)

.下一字母是否与该点字母相同

.该点为第几个辅音字母

(2).否

清零连续辅音数,标记字母相同

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char s[3010],ans[5050];
int main()
{
scanf("%s",s);
int cnt = 0,same = 1,k=0,len = (int)strlen(s);
for(int i=0;i<len;i++)
{
ans[k++] = s[i];
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u') cnt = 0,same = 1;
else
{
cnt++;
int pos = i+1;
if(pos==len||s[pos]=='a'||s[pos]=='e'||s[pos]=='i'||s[pos]=='o'||s[pos]=='u') continue;
if(s[pos]!=s[pos-1]) same = 0;
if(same) continue;
if(cnt>=2)
{
ans[k++] = ' ';
cnt = 0;
same = 1;
}
}
}
puts(ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: