Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】
C. 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.
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
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.
hellno
hell no
abacaba
abacaba
asdfasdf
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 }
作 者:Angel_Kitty
出 处:https://www.cnblogs.com/ECJTUACM-873284962/
关于作者:阿里云ACE,目前主要研究方向是Web安全漏洞以及反序列化。如有问题或建议,请多多赐教!
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力!
欢迎大家关注我的微信公众号IT老实人(IThonest),如果您觉得文章对您有很大的帮助,您可以考虑赏博主一杯咖啡以资鼓励,您的肯定将是我最大的动力。thx.
我的公众号是IT老实人(IThonest),一个有故事的公众号,欢迎大家来这里讨论,共同进步,不断学习才能不断进步。扫下面的二维码或者收藏下面的二维码关注吧(长按下面的二维码图片、并选择识别图中的二维码),个人QQ和微信的二维码也已给出,扫描下面👇的二维码一起来讨论吧!!!
欢迎大家关注我的Github,一些文章的备份和平常做的一些项目会存放在这里。