codeforces 858C Did you mean... (贪心)

题目链接: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; // f: 当前 block 是否只含一个字母
	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;
}
posted @ 2020-10-18 13:33  Tartarus_li  阅读(90)  评论(0编辑  收藏  举报