STL算法之count. count_if
来源:互联网 发布:php数组最大长度限制 编辑:程序博客网 时间:2024/05/18 05:10
转接自STL算法
count(beg,end,value) 返回值为value元素个数
count_if(beg,end,Pred) 统计并返回满足谓词Pred的值个数
1.count()用法示例:
#include <iostream>#include <vector>using namespace std;//count(beg,end,value) 返回值为value元素个数void test(const vector<int> &vec){ //统计值为3的个数 cout << count(vec.begin(), vec.end(),3);}int main(){ vector<int> vec{ 1,2,3,3,4,5,6,3,7,8,3 }; test(vec); system("pause"); return 0;}
2.count_if用法及示例:
#include <iostream>#include <vector>#include <algorithm>using namespace std;//count_if(beg,end,Pred) 统计并返回满足谓词Pred的值个数void test(const vector<int> &vec){ auto f = [](const int& value) { return value % 2 == 0; }; cout << count_if(vec.begin(), vec.end(), f);}int main(){ vector<int> vec{ 1,2,3,3,4,5,6,3,7,8,3 }; test(vec); system("pause"); return 0;}
阅读全文
1 0
- STL算法之count. count_if
- STL之 count 和 count_if
- 非变异算法之计数(count, count_if)
- STL 之count,count_if,max,max_element,min,min_element和random_shuffle
- STL 之count,count_if,max,max_element,min,min_element和random_shuffle
- 非修改性序列算法之count和count_if
- STL中count和count_if的妙用
- STL 计数(count,count_if)的用法
- STL algorithm算法count_if(11)
- STL 统计vector容器中指定对象元素出现的次数:count()与count_if()算法
- count,count_if
- count count_if
- 泛型算法系列9:count()&&count_if()
- STL_算法_元素计数(count、count_if)
- STL算法 count_if函数 accumulate函数
- 简单的程序诠释C++ STL算法系列之七:count_if
- STL_ count,count_if用法
- count与count_if详解
- 【PAT】【Advanced Level】1027. Colors in Mars (20)
- 下一代 Web 应用模型 —— Progressive Web App
- 解决远程连接mysql错误1130 远程连接Mysql服务器的数据库,错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to co
- centos上GITLAB的搭建
- 读书笔记:Android开发艺术探索之第6章 android的Drawable
- STL算法之count. count_if
- SpringMVC导出CSV文件中文出现乱码解决方案
- Spring 依赖注入
- 【数据结构】有序树和无序树的区别
- 1.文档流(标准流)、浮动布局
- 原型继承1.2.8
- ubuntu 任务栏 放到下面
- RHEL版本与内核对应表
- springboot mybatis