• 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 }
  • 相关阅读:
    13_函数的基本使用简介
    12_goto语句的使用
    11_for语句的使用
    10_switch语句的使用
    09_if条件语句的使用
    08_类型别名(类型声明)
    day-32网络编程
    day-31网络编程
    day-30网络编程
    day-29元类、异常处理
  • 原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/7544265.html
Copyright © 2020-2023  润新知