1 条题解

  • 0
    @ 2025-5-26 20:55:33
    #include <iostream>
    #include <string>
    using namespace std;
    
    bool is_vowel(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
    
    bool is_acceptable(const string& s) {
        bool has_vowel = false;
        int vowel_count = 0, consonant_count = 0;
    
        for (int i = 0; i < s.size(); ++i) {
            if (is_vowel(s[i])) {
                has_vowel = true;
                vowel_count++;
                consonant_count = 0;
            } else {
                consonant_count++;
                vowel_count = 0;
            }
    
            if (vowel_count >= 3 || consonant_count >= 3)
                return false;
    
            if (i >= 1 && s[i] == s[i - 1]) {
                if (!(s[i] == 'e' || s[i] == 'o'))
                    return false;
            }
        }
    
        return has_vowel;
    }
    
    int main() {
        string word;
        while (cin >> word && word != "end") {
            if (is_acceptable(word))
                cout << "<" << word << "> is acceptable." << endl;
            else
                cout << "<" << word << "> is not acceptable." << endl;
        }
        return 0;
    }
    
    • 1

    信息

    ID
    576
    时间
    1000ms
    内存
    10MiB
    难度
    5
    标签
    递交数
    2
    已通过
    1
    上传者