我想做一个函数来计算字符串中的辅音,所以我试着这样做:
def vowel_count(foo):
count = 0
for i in foo:
if not i == 'a' and i == 'e' and i ... and i == 'O' and i == 'U':
count += 1
return count
Run Code Online (Sandbox Code Playgroud)
但这样做非常难看和繁琐,更多的条件更多.有没有办法将它们组合在一起?
我已经用递归方式打印向量的所有元素,但它返回无意义!它抛出了一个非常奇怪的异常:
Exception thrown: read access violation.
std::vector<int,std::allocator<int> >::operator[](...) returned nullptr.
Run Code Online (Sandbox Code Playgroud)
它输出: 12358000
这是代码。我犯了什么错误?
#include <iostream>
#include <vector>
using namespace std;
int printVec(vector<int>* foo) {
if ((*foo).empty())
return 0;
else {
cout << (*foo)[0];
printVec(foo + 4);
}
}
int main() {
vector<int> ref{ 1,2,3,4,5,6,7,8,9,0 };
printVec(&ref);
}
Run Code Online (Sandbox Code Playgroud)