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

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;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值