璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup3880
problems
名称提示问题
题目编号P3880
题目链接luogu.com.cn/…
来源Luogu
算法分类字符串, 模拟
难易程度容易

提示问题

想法

按题目要求模拟,就是判断需要多写几个。

代码实现

#include<cstdio>
#include<cmath>
#include<cstring>
const int N = 60;
char str[N], ans1[N], ans2[N], ans3[N];
char y[11] = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
bool check1(char x) {
	if(x >= 'a' && x <= 'z')
		return true;
	if(x >= 'A' && x <= 'Z')
		return true;
	return false;
}
bool check2(char x) {
	for(int i=0; i<10; i++)
		if(y[i] == x)
			return true;
	return false;
}
int main() {
	fgets(str, sizeof(str), stdin);
	int len = strlen(str), cnt = 0;
	if(str[len-1] == '\n') {
		str[len-1] = '\0';
		len --;
	}
	for(int i=0; i<len; i++) {
		if(check1(str[i])) {
			cnt++;
			ans1[i] = '.';
		}
		else
			ans1[i] = str[i];
	}
	int n = round(cnt / 3.0), sit = 0;
	for(int i=0; i<len; i++) {
		if(check1(str[i])) {
			if(n) {
				ans2[i] = str[i];
				n--;
				if(n == 0)
					sit = i;
			} 
			else
				ans2[i] = '.';
		}
		else
			ans2[i] = str[i];
	}
 
	bool flag = false;
	for(int i=sit+1; i<len; i++)
		if(check2(str[i])) {
			flag = true;
			break;
		}
 
	if(flag) {
		for(int i=0; i<len; i++) {
			if(check2(str[i]))
				ans3[i] = str[i];
			else
				ans3[i] = ans2[i];
		}
	}
	else {
		n = round(cnt / 3.0 * 2);
		for(int i=0; i<len; i++) {
			if(check1(str[i])) {
				if(n) {
					ans3[i] = str[i];
					n--;
				} 
				else
					ans3[i] = '.';
			}	
			else
				ans3[i] = str[i];
		}
	}
	printf("%s\n%s\n%s", ans1, ans2, ans3);
	return 0;
} 
/app/www/public/data/pages/icpc/problems/luogup3880.txt · 最后更改: 2024/03/09 05:40 由 温婕莺