poj_3371
一道模拟题,写的有点麻烦
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; bool fun(char c) { if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U'||c=='y'||c=='Y') return true; else return false; } int main() { int word=0,sen=0,syl=0; char s[1000]; while(scanf("%s",s)!=EOF) { int len=0,y=0; int i; for(i=0; s[i]!='\0'; i++) { if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')) { len++; if(fun(s[i])) { if(s[i]=='e') { if(!((s[i+1]>='a'&&s[i+1]<='z')||(s[i+1]>='A'&&s[i+1]<='Z'))&& s[i-1]=='l') { syl++; y++; } else if(!fun(s[i+1])&&((s[i+2]>='a'&&s[i+2]<='z')||(s[i+2]>='A'&&s[i+2]<='Z'))) { if((s[i+1]>='a'&&s[i+1]<='z')||(s[i+1]>='A'&&s[i+1]<='Z')) {syl++; y++; } } else if(!fun(s[i+1])&&((s[i+1]>='a'&&s[i+1]<='z')||(s[i+1]>='A'&&s[i+1]<='Z'))&&(s[i+1]!='s')&&(s[i+1]!='d')) {syl++; y++; } else if(fun(s[i-1])&&!((s[i+2]>='a'&&s[i+2]<='z')||(s[i+2]>='A'&&s[i+2]<='Z'))&&((s[i+1]=='s')||(s[i+1]=='d'))) { syl++;y++; } else if(fun(s[i-1])&&!((s[i+1]>='a'&&s[i+1]<='z')||(s[i+1]>='A'&&s[i+1]<='Z'))) { syl++;y++; } } else if(!fun(s[i+1])) {syl++;y++; } } if(len<=3) { if(!((s[i+1]>='a'&&s[i+1]<='z')||(s[i+1]>='A'&&s[i+1]<='Z'))) { syl++; syl-=y; y=0; continue; } } } else if(s[i]==',') { word++; y=0; len=0; } else if(s[i]=='.' || s[i]=='?' || s[i]==':' || s[i]==';' || s[i]=='!') { word++; sen++; y=0; len=0; } } if((s[i-1]>='a'&&s[i-1]<='z')||(s[i-1]>='A'&&s[i-1]<='Z')) { word++; y=0; len=0; } memset(s,'\0',sizeof(s)); } printf("%.2f\n",206.835-1.015*(double)word/(double)sen-84.6*(double)syl/(double)word); return 0; }