题目大意
轻松度的定义: 206.835−1.015∗wordssentences−84.6∗syllableswords
具体的遵循一下规则:
- sentences以句号(.),感叹号(!),冒号(:)和分号(;)分开
- 连续的不含空格的字符串除去开头和末尾的标点后视为一个单词
单词中的一个元音(a,e,i,o,u,y)作为单词中的一个音节,但服从以下规则
- 忽略-es,-ed,-e结尾的(-le结尾除外)
- 长度为三个及以下的单词被视为单音节单词
- 连续的音节被视为一个音节
输入包含大小写
标点符号包括(. ? and ! : ; , ” - ’ )
总结
模拟题没什么好分析的,每次交这种题心里都特别没谱,怕哪里细节又没注意到了,上一道题交了15次,还好这题一次过,不然心态真要崩了。
代码
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
using namespace std;
int sentences;
int words;
int syllables;
void Into_lower(char s[])//转小写
{
int len = strlen(s);
for(int i=0;i<len;i++)
{
if(s[i]>='A' && s[i]<='Z')s[i]=s[i]+32;
}
}
void Delete_punctuation(char s[])//除去标点符号
{
int len=strlen(s);
if( !(s[len-1]>= 'a' && s[len-1]<='z') ){s[len-1]='\0';len--;}
if( !(s[0]>='a' && s[0]<='z') )
{
for(int i=0;i<len-1;i++)s[i]=s[i+1];
s[len-1]='\0';
len--;
}
}
bool Has_sentence(char s[])//判断是否含有句子结束的符号,只看s末尾的符号
{
int len=strlen(s);
if(s[len-1]=='.' || s[len-1]=='!' || s[len-1]==':' || s[len-1]==';')return 1;
else return 0;
}
int Count_syllable(char s[])//返回s中的syllable个数
{
int len=strlen(s);
int ans=0;
int letters=0;
for(int i=0;i<len;i++)if(s[i]>='a' && s[i]<='z')letters++;
if(letters<=3){return 1;}//字母数小于等于三的情况
if(s[len-2]=='e' && (s[len-1]=='s' || s[len-1]=='d') )len-=2;
else if(s[len-1]=='e' && s[len-2]!='l'){len-=1;}
int flag=0;
for(int i=0;i<len;i++)
{
if( (s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' || s[i]=='y') )
{
if(flag==0)ans++;
flag=1;
}
else flag=0;
}
return ans;
}
int main()
{
//cout<<(206.835-(1.015*61.0/2.0)-26.09)*61.0/84.6<<endl;
char s[100];
sentences=0;
words=0;
syllables=0;
while(scanf("%s",s)!=EOF)
{
//if(s[0]=='0')break;
Into_lower(s);
words++;
if(Has_sentence(s)==1)sentences++;
Delete_punctuation(s);
syllables+=Count_syllable(s);
//cout<<" "<<Count_syllable(s)<<endl;
}
//cout<<sentences<<" "<<words<<" "<<syllables<<endl;
double ans=0;
ans=206.835-1.015*((double)words/(double)sentences)-84.6*((double)syllables/(double)words);
cout<<fixed<<setprecision(2)<<ans<<endl;
return 0;
}