题意: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; }