题目链接:http://poj.org/problem?id=1575
题意让我们判断所给的字符串是否满足所给的条件:
1,至少有一个元音字母
2,不能出现三个元音连续或者三个辅音连续
3,除了ee和oo不能出现两格字母连续
我用j1,j2,j3分别判断这三个条件,其中j2的if语句还是写得有点特色的,看是否三个或和三个且的值一样,嘿嘿
具体见代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std;
char ch[25]; int len;
bool y(char q) { if (q=='a'||q=='e'||q=='i'||q=='o'||q=='u') return 1; return 0; }
bool j1() { for(int i=0;i<len;i++) if(y(ch[i])) return 1; return 0; }
bool j2() { if(len<3) return 1; for(int i=0;i<=len-3;i++) if((y(ch[i])&&y;(ch[i+1])&&y;(ch[i+2]))==(y(ch[i])||y(ch[i+1])||y(ch[i+2]))) return 0; return 1; }
bool j3() { if(len<2) return 1; for(int i=0;i<=len-2;i++) if((ch[i]==ch[i+1])&&ch;[i]!='e'&&ch;[i]!='o') return 0; return 1; }
int main() { while(cin>>ch) { if(strcmp(ch,"end")==0) break; len=strlen(ch); cout<<"<"<<ch<<"> is "; if(!(j1()&&j2;()&&j3;())) cout<<"not "; cout<<"acceptable."<<endl; } }
|