Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C 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 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代码:

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=3e3;
 4 int n;
 5 int a[N+10],is[400];
 6 char s[N+10];
 7 int main(void)
 8 {
 9     is['a']=is['e']=is['i']=is['o']=is['u']=1;
10     cin>>(s+1);
11     n=strlen(s+1);
12     int cnt=0;
13     for(int i=1;i<=n;i++)
14     {
15         if(!is[s[i]])
16         {
17             cnt++;
18             if(cnt>=3)
19             {
20                 bool ok=true;
21                 int j=max(1,i-2);
22                 for(int k=j;k<=i-1;k++)//前面的3个都和它一样吗
23                     if(s[k]!=s[i])
24                         ok=false;
25                 if(ok)//如果是的话
26                 {
27                     cout<<s[i];
28                     int k=i;
29                     while(k+1<=n&&s[k+1]==s[i])//往后一直找和它一样的
30                     {
31                         k++;
32                         cout<<s[k];
33                     }
34                     cnt=2;
35                     i=k;//cnt变成2了,指向下一个。
36                 }
37                 else//不是的话。只能分割了。
38                 {
39                     cout<<' '<<s[i];
40                     cnt=1;
41                 }
42             }
43             else
44                 cout<<s[i];//没3个
45         }
46         else//是元音直接输出
47         {
48             cout<<s[i];
49             cnt=0;
50         }
51     }
52     //连续出现
53 }
复制代码

 

posted @   Angel_Kitty  阅读(463)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示
哥伦布
14°
14:09发布
哥伦布
14:09发布
14°
大雨
南风
3级
空气质量
相对湿度
93%
今天
中雨
14°/19°
周日
中雨
5°/19°
周一
1°/11°