• Codeforces 861 C Did you mean... 模拟 暴力


      题目链接: http://codeforces.com/contest/861/problem/C

      题目描述: 给你一个字符串, 如果连续的辅音字母超过三个就不好了, 但是如果是一种字母不管多少都是好的, 现在让你分割这个字符串, 让它成为若干的好的字符串

      解题思路: 模拟即可, 碰到辅音就向后面走, 直到元音停下, 然后记录应该插入空格的位置

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <map>
    #include <iterator>
    #include <string>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <cstring>
    using namespace std;
    
    typedef long long ll;
    
    const int maxn = 3e3+100;
    int ans[maxn];
    char s[maxn];
    map<char, int> m;
    
    void build() {
        m['a'] = 1, m['e'] = 1, m['i'] = 1, m['o'] = 1, m['u'] = 1;
    }
    
    int main() {
        build();
        scanf("%s", s+1);
        int n = (int)strlen(s+1);
        for( int i = 1; i <= n; i++ ) {
            if( !m[s[i]] ) {
                int k = 0;
                for( int j = i; j <= n; j++ ) {
                    if( m[s[j]] ) {
                        i = j;
                        break;
                    }
                    k++;
                    if( k >= 3 ) {
                        
                        if( s[j]==s[j-1] && s[j]==s[j-2] ) {
                            for( int t = j+1; t <= n; t++ ) {
                                if( s[t] != s[t-1] ) {
                                    if( m[s[t]] ) {
                                        i = t;
                                        break;
                                    }
                                    else {
                                        ans[t] = 1;
                                        i = t-1;
                                        break;
                                    }
                                }
                            }
                        }
                        else {
                            ans[j] = 1;
                            i = j-1;
                            break;
                        }
                        break;
                    }
                }
            }
        }
    //    for( int i = 1; i <= n; i++ ) {
    //        cout << ans[i] << " ";
    //    }
    //    cout << endl;
        for( int i = 1; i <= n; i++ ) {
            if( ans[i] ) {
                printf( " %c", s[i] );
            }
            else {
                printf( "%c", s[i] );
            }
        }
        printf( "
    " );
        return 0;
    }
    View Code

      思考: 之前因为没有加break  T 了一发, 仔细!  仔细一点儿啊!!!!

  • 相关阅读:
    初步认识数据库系统
    相对路径与绝对路径
    数据库系统的结构抽象与演变
    unity物体穿过地面
    Matlab imadjust详解(转载)
    div水平垂直居中及块内元素居中
    Java中HashMap的使用
    Java中HashSet的使用
    Java中数组的使用
    数据结构_堆
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7614723.html
Copyright © 2020-2023  润新知