c++ - 仅在 C++ 中使用递归删除元音和特殊字符,同时对辅音进行修饰
问题描述
我正在尝试编写一个递归函数,从短语中删除元音、特殊字符和空格并将辅音大写。我很难想出一个纯粹的递归函数。也不知道如何在 C++ 中链接函数。可以toUpperCase()
和isalpha()
一起使用吗?有没有办法将子句中的两个条件结合起来else if
放在else
子句中?
bool isVowel(char ch) {
if (ch == 'A' || ch == 'E' || ch == 'I' ||
ch == 'O' || ch == 'U' || ch == 'Y') {
return true;
}
else {
return false;
}
}
string onlyConnectize(string phrase) {
phrase = toUpperCase(phrase);
// base case
if (phrase.empty()) {
return "";
}
else if (!isalpha(phrase[0])) {
return "";
}
else if (isVowel(phrase[0])) {
return "";
}
else {
return phrase[0] + onlyConnectize(phrase.substr(1));
}
}
解决方案
推荐阅读
- datetime - Dataweave 2 - 无法将字符串强制转换为 DateTime
- transactions - 如何在 Keycloak SPI 扩展中编写简单的事务包装器?
- python - 在执行 I/O 密集型任务时,20 个进程中的 400 个线程优于 4 个进程中的 400 个线程
- css - 在 p:dataTable 中过滤后禁用列大小调整
- javascript - 在javascript中查找布尔值的变量名
- alloy - 合金分析仪没有准确执行我的运行命令
- delphi - 类或记录(
) - c++ - 如何处理 std::vector<...>::size_type 为 int
- java - 增量运算符在运行和调试时的工作方式不同
- r - R Shiny中的直方图