题目链接: http://codeforces.com/contest/861/problem/C
题目描述: 给你一个字符串, 如果连续的辅音字母超过三个就不好了, 但是如果是一种字母不管多少都是好的, 现在让你分割这个字符串, 让它成为若干的好的字符串
解题思路: 模拟即可, 碰到辅音就向后面走, 直到元音停下, 然后记录应该插入空格的位置
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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; }
思考: 之前因为没有加break T 了一发, 仔细! 仔细一点儿啊!!!!