POJ 3371.Flesch Reading Ease

题目:http://poj.org/problem?id=3371

AC代码(C++):

#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <algorithm>
#include <string.h>
#include <math.h>

#define INF 0x3f3f3f3f
#define eps 1e-8
typedef unsigned long long ULL;

using namespace std;

char word[1000];
int words, sents, syllas;

bool isVowel(char a) {
	if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y')return true;
	else return false;
}

int main() {
	words = 0;
	sents = 0;
	syllas = 0;
	while (cin >> word) {
		words++;
		char tmp = word[strlen(word) - 1];
		if (tmp == '.' || tmp == '?' || tmp == '!' || tmp == ';' || tmp == ':')sents++;
		if ((tmp<'a' || tmp>'z') && (tmp<'A' || tmp>'Z'))word[strlen(word) - 1] = '\0';
		if (strlen(word) <= 3) {
			syllas++;
			continue;
		}
		for (int i = 0; word[i] != '\0'; i++)if (word[i] >= 'A'&&word[i] <= 'Z')word[i] -= 'A' - 'a';
		for (int i = 0; word[i] != '\0'; i++) {
			if (isVowel(word[i])) {
				if (!isVowel(word[i + 1])) {
					syllas++;
				}
			}
		}
		if (word[strlen(word) - 2] == 'e'&&word[strlen(word) - 1] == 's'&&!isVowel(word[strlen(word) - 3]))syllas--;
		else if (word[strlen(word) - 2] == 'e'&&word[strlen(word) - 1] == 'd'&&!isVowel(word[strlen(word) - 3]))syllas--;
		else if (word[strlen(word) - 2] != 'l'&&word[strlen(word) - 1] == 'e'&&!isVowel(word[strlen(word) - 2]))syllas--;
	}

	double ans = 206.835 - 1.015*((double)words / sents) - 84.6*((double)syllas / words);
	printf("%.2lf", ans);

	//system("pause");
}
总结: 很坑爹的题, 不建议做. 原理很简单, 就是计数, 但是我认为题目没讲清楚, 题目中给出的符号很多根本不出现, 如果出现了就很难做(比如引号什么的), 会出现的符号在程序中列出来了. 还有一个坑就是如果需要忽略的后缀前面已经有了元音字母, 注意不要重复忽略.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值