algorithm与numeric的一些常用函数
numeric中的accumulated的基本用法:
来自:https://blog.csdn.net/u011499425/article/details/52756242
#include <vector>
#include<numeric>
#include<iostream>
#include <string>
using namespace std;
struct Grade
{
string name;
int grade;
};
int cmp(int a, Grade b)
{
return a + b.grade;
}
int main()
{
Grade subject[] = {
{ "English", },
{ "Biology", },
{ "History", }
}; //int sum = accumulate(subject, subject + 3, 0, [](int a, Grade b) {return a + b.grade; });
int sum = accumulate(subject, subject + , , cmp);
cout << sum << endl; system("pause");
return ;
}
algorithm的count:利用等于操作符,把标志范围内的元素与输入值比较,返回相等元素个数。
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[] = { , , , };
int k = count(a, a + ,);
cout << k << endl;
return ;
}
unique:去重;
algorithm与numeric的一些常用函数的更多相关文章
- STL algorithm 头文件下的常用函数
algorithm 头文件下的常用函数 1. max(), min()和abs() //max(x,y)和min(x,y)分别返回x和y中的最大值和最小值,且参数必须时两个(可以是浮点数) //返回3 ...
- algorithm头文件下的常用函数
algorithm头文件常用高效函数 max() max(a, b)返回a和b中的最大值,参数必须是两个(可以是浮点型). 1 #include <iostream> 2 #include ...
- algorithm下的常用函数
algorithm下的常用函数 max(),min(),abs() max(x,y)返回x和y中最小的数字 min(x,y)返回x和y中最大的数字 abs(x)返回x的绝对值,注意x应当是整数,如果是 ...
- 【c++进阶:c++ algorithm的常用函数】
c++ algorithm的常用函数 https://blog.csdn.net/hy971216/article/details/80056933 reverse() reverse(it,it2) ...
- C++中的算法头文件<algorithm>,<numeric>和<functional>
算法部分主要由头文件<algorithm>,<numeric>和<functional>组成.<algorithm>是所有STL头文件中最大的一个,它是 ...
- Oracle常用函数:DateDiff() 返回两个日期之间的时间间隔自定义函数
首先在oracle中没有datediff()函数可以用以下方法在oracle中实现该函数的功能:1.利用日期间的加减运算天:ROUND(TO_NUMBER(END_DATE - START_DATE) ...
- Oracle分析函数及常用函数: over(),rank()over()作用及用法--分区(分组)求和& 不连续/连续排名
(1) 函数: over()的作用及用法: -- 分区(分组)求和. sum() over( partition by column1 order by column2 )主要用来对某个字 ...
- MySQL常用函数介绍
MySQL常用函数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.操作符介绍 1>.操作符优先级 mysql; +----------+ | +----------+ ...
- 【算法专题】工欲善其事必先利其器—— 常用函数和STL
一. 常用函数 #include <stdio.h> int getchar( void ); //读取一个字符, 一般用来去掉无用字符 char *ge ...
随机推荐
- app-web 开发 追溯debug
1.iphone5 运行vue项目时,方法格式:fun(){}这种格式容易不显示页面 2.vue未绑定上数据有可能是js文本过大,手机内存不足引起的 3.根据方法走向追溯debug 4.一定要用try ...
- python3: print()函数:def,end关键字介绍
print()函数是最最普通常见的函数,我们常用的方式为类似这种的没有任何设置的“ print("今天是个好日子") ” 的简单输出. 其实print()函数中含有如下几个关键字, ...
- day 10 - 2 函数练习
1.写函数 接收 n 个数字 求这些参数数字的和 def sum_func(*args): total = 0 for i in args: total += i return total prin ...
- linux 启动管理
- 不使用setCustomView,设置ActionBar标题居中
仅供参考,有太多自定义标题栏需求时,还是建议使用setCustomView https://blog.csdn.net/chiceT/article/details/50455358
- Redis安装完后redis-cli无法使用(redis-cli: command not found)
之前安装redis后客户端无法使用,即redis-cli执行后报找不到的错误.这主要是安装redis的时候没有把客户端装上,在StackOverFlow上找到了一种只安装redis cli的方法,这里 ...
- MySQL登录报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@pisphkdcbsql01 mysql3307]# /opt/mysql3307/bin/mysql -upisp -ppisp@ mysql: [Warning] Using a pa ...
- 028_shell脚本递归求值
一. #!/bin/sh factorial() { if [ "$1" -gt "1" ]; then i=`expr $1 - 1` j=`factoria ...
- mysql多表关联update修改操作
UPDATE province_yunnan_salary s1 JOIN province_guangdong_salary s2 ON s1.user_name= s2.user_name S ...
- Jmeter之csv参数化
创建数据源csv文件 在线程组中添加CSV Data Set Config 1.添加CSV Data Set Config 添加CSV Data Set Config 2.配置CSV Data Set ...