codeforces 858C Did you mean... (貪心)
阿新 • • 發佈:2020-10-18
題目連結:https://codeforces.com/problemset/problem/858/C
一出現語法錯誤就要斷開
注意小細節
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #include<stack> #include<queue> using namespace std; typedef long long ll; const int maxn = 3010; int n; int bas[30]; char s[maxn]; ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; } int main(){ scanf("%s",s+1); n = strlen(s+1); bas['a'-'a'] = bas['e' - 'a'] = bas['i' - 'a'] = bas['o' - 'a'] = bas['u' - 'a'] = 1; int cnt=0, f=0; for(int i=1;i<=n;++i){ if(bas[s[i] - 'a']){ cnt = 0; f = 0; printf("%c",s[i]); }else{ if(s[i] != s[i-1]){ if(cnt >= 2){ printf(" %c",s[i]); cnt = 1; f = 0; }else{ printf("%c",s[i]); ++cnt; if(i!=1 && !bas[s[i-1] - 'a']) f=1; } }else{ if(!f){ printf("%c",s[i]); ++cnt; }else{ if(cnt >= 2){ printf(" %c",s[i]); cnt = 1; f = 0; }else{ printf("%c",s[i]); ++cnt; } } } } } printf("\n"); return 0; }