#include #include using namespace std;

bool isVowel(char c) { c = tolower(c); return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); }

string krunch(string sentence) { string result = ""; string word = ""; bool allVowels = true; for (int i = 0; i < sentence.length(); i++) { if (sentence[i] == ' ' || sentence[i] == '.') { if (allVowels) { result = result.substr(0, result.length() - 1); } else { result += word; } if (sentence[i] == '.') { result += '.'; } result += ' '; word = ""; allVowels = true; } else { if (!isVowel(sentence[i])) { allVowels = false; word += sentence[i]; } } } return result; }

int main() { string sentence; getline(cin, sentence); cout << krunch(sentence) << endl; return 0;

题目描述:KrunCh 是一种对单词的操作 Krunch 一个单词其实就是把该单词中所有的元音字母 a、e、i、o、u 去除不管它是大写还是小写。编写一个程序对一个句子进行 Krunch 操作。需要注意的是:如果一个单词完全由元音字母组成 Krunch 后它将化为乌有这时你需要去掉多余的空格使它看上去仍像一个句子。输入:一个不超过 72 个字符的句子标点后没有元音字母。输出: Krunch 操作后

原文地址: https://www.cveoy.top/t/topic/ieQd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录