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 63 64 |
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <iomanip> #include <cmath> #include <set> using namespace std; int main(int argc, char *argv[]) { string str; while (cin >> str) { if (str == "end"){ break; } //vowel check bool vowelflag = false; for (int i = 0;i < str.size();i++) { if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u'){ vowelflag = true; break; } } bool onajiflag = false; char prev = str[0]; for (int i = 1;i < str.size();i++) { if(str[i] == prev){ if(prev == 'e' || prev == 'o'){ continue; }else { onajiflag = true; break; } } prev = str[i]; } bool threeflag = false; for (int i = 0;i < (int)str.size()-2;i++) {//kengkengkeng bool isvowel[3] = {false,false,false}; for (int j = 0;j <= 2;j++){ if(str[i+j] == 'a' || str[i+j] == 'e' || str[i+j] == 'i' || str[i+j] == 'o' || str[i+j] == 'u'){ isvowel[j] = true; } } if((isvowel[0] && isvowel[1] && isvowel[2]) || (!isvowel[0] && !isvowel[1] && !isvowel[2])){ threeflag = true; break; } } //cout << vowelflag << onajiflag << threeflag << endl; if(vowelflag && !onajiflag && !threeflag) cout << '<' << str << '>' << " is acceptable." << endl; else cout << '<' << str << '>' << " is not acceptable." << endl; } return 0; } |
c++课后作业系列,但是有坑。
注意看我标kengkengkeng那里,string.size()默认返回的类型是unsigned long,当字符串长度为1时,减去2会发生啥估计大家也都清楚,