zoukankan      html  css  js  c++  java
  • Codeforces Round #434 C

    Did you mean...

    题意:a e i o u是元音,在一个字符串里不能有3个连续的辅音,但是3个及以上相同的连续辅音可以,否则就要用空格隔开,给你字符串,用最少的空格把字符串变为合法

    思路:模拟就是了

    AC代码:

    #include "iostream"
    #include "iomanip"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #pragma comment(linker, "/STACK:102400000,102400000")
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a,x) memset(a,x,sizeof(a))
    #define step(x) fixed<< setprecision(x)<<
    #define mp(x,y) make_pair(x,y)
    #define pb(x) push_back(x)
    #define ll long long
    #define endl ("
    ")
    #define ft first
    #define sd second
    #define lrt (rt<<1)
    #define rrt (rt<<1|1)
    using namespace std;
    const ll mod=1e9+7;
    const ll INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const double PI=acos(-1.0);
    const int N=1e5+100;
    
    char s[30005];
    int is[1005],ans[30005];
    
    int main(){
        cin>>s+1;
        is['a']=1, is['e']=1, is['i']=1, is['o']=1, is['u']=1;
        int n=strlen(s+1);
        for(int i=1; i<=n; ++i){
            if(!is[s[i]]){
                int k=0;
                for(int j=i; j<=n; ++j){
                    if(is[s[j]]){
                        i=j;
                        break;
                    }
                    k++;
                    if(k>2){
                        if(s[j] == s[j-1] && s[j-1]==s[j-2]){
                            for(int t=j+1; t<=n; ++t){
                                if(s[t]!=s[t-1]){
                                    if(is[s[t]]){
                                        i=t;
                                        break;
                                    }
                                    ans[t-1]=1;
                                    i=t-1;
                                    break;
                                }
                            }
                        }
                        else{
                            ans[j-1]=1;
                            i=j-1;
                            break;
                        }
                        break;
                    }
                }
            }
        }
        for(int i=1; i<=n; ++i){
            cout<<s[i];
            if(ans[i]) cout<<" ";
        }
        return 0;
    }
  • 相关阅读:
    为初学者解释下命名空间
    面向对象的思想
    SELECT查询结果集INSERT到数据表
    SQL Server事务
    Sql Server中的谓词和运算符
    SQL查询语句执行的逻辑顺序
    浏览器中的流
    CSS盒子模型
    ArcGIS提取水系并进行生态敏感性分析
    ENVI提取水系并进行生态敏感性分析
  • 原文地址:https://www.cnblogs.com/max88888888/p/7552395.html
Copyright © 2011-2022 走看看