题目来源
题意:
给出一篇规范的文章,求其 句子数、单词数 和 音节数把这3个值代入题目给出的公式,输出其结果,保留2位小数。
标记单词分隔符: 逗号(,) 和 空格( )
句子分隔符:句号(.) 问号(?) 冒号(:) 分号(;) 感叹号(!)
音节处理要求:
(1)当单词总长度<= 3 时,音节数无条件+1
(2) 当单词总长度 > 3 时,单词中每出现一个元音字母(a、e、i、o、u、y),音节数+1。
但是连续的(>=2)元音字母只按1个音节计算,且当单词后缀为-es、-ed和-e时,后缀的元音字母e不列为音节数计算。
但是后缀-le例外,要计算音节数。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#define inf 0x3f3f3f3f
#define ll long long
#define mod 99991
using namespace std;
char str[1000];
int words = 0;
int sentences = 0;
int syllables = 0;
//判断是否为字符
bool isChar(char ch){
if(ch>='a'&&ch<='z')return true;
if(ch>='A'&&ch<='Z')return true;
return false;
}
//判断是否为元音
bool isVowel(char ch){
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='y'){
return true;
}
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'||ch=='Y'){
return true;
}
return false;
}
bool isOk(int k){
if(str[k+1]=='d' && !isChar(str[k+2]))return true;
if(str[k+1]=='s' && !isChar(str[k+2]))return true;
if(str[k-1]!='l' && !isChar(str[k+1]))return true;
return false;
}
int main(){
//freopen("out.txt","w",stdout);
while(~scanf("%s",str)){
int wordLen = 0;
bool flag = false;
int syNum = 0;
int i=0;
for(; str[i]; ++i){
if(isChar(str[i])){
wordLen++;
if(wordLen <= 3){
if(!isChar(str[i+1])){
syllables++;
syllables -= syNum;
syNum = 0;
continue;
}
}
if(isVowel(str[i])){
if(str[i]=='e'){
if(isOk(i)){
continue;
}
}
if(!flag){
flag = true;
syllables++;
syNum++;
continue;
}
else continue;
}
flag = false;
}
else if(str[i]==','){
flag = false;
wordLen = 0;
syNum = 0;
words++;
}
else if(str[i]=='.'||str[i]=='?'||str[i]==':'||
str[i]==';'||str[i]=='!'){
flag = false;
wordLen = 0;
syNum = 0;
words++;
sentences++;
}
}
if(isChar(str[i-1])){
words++;
}
}
double ans = 206.835-1.015*(double)words/(double)sentences-84.6*(double)syllables/(double)words;
printf("%.2f\n",ans);
return 0;
}
本文介绍了一种用于评估文章阅读难度的算法实现。通过计算文章中的句子数、单词数及音节数,并依据特定公式得出文章复杂度得分,有助于了解读者理解文章所需的大概努力程度。该算法特别关注了英文单词的音节计数规则,考虑了特殊情况如-es、-ed后缀等。
3835

被折叠的 条评论
为什么被折叠?



