#include<iostream>
#include<string>
#include<vector>
#include<numeric>
using namespace std;
class solution {
public:
int func(vector<string>& words, int left, int right) {
auto get = [](char x) -> int { return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'); }; //Lambda函数判断x是否为元音字母
auto getfunc = [&get](string& x) -> int {return get(x[0]) & get(x.back()); }; //Lambda函数调用上面的Lambda函数来判断x是否首尾都为元音字母
return accumulate(words.begin() + left, words.end() + right + 1, 0, [&getfunc](int sum, string& x) {return sum + getfunc(x); });//求和器
}
};
int main() {
solution s;
vector<string> words = {"are", "amy", "u"
刷题DAY 3 统计元音字符串数 C++
最新推荐文章于 2024-01-14 02:30:36 发布