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 ...
随机推荐
- 转载-MySQL binlog三种模式及设置方法
原文地址:http://www.cnblogs.com/yangliheng/p/6187327.html 1.1 Row Level 行模式 日志中会记录每一行数据被修改的形式,然后在slave端 ...
- xgboost安装 win10 64位 annaconda
重点参考三个网站: https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_XGBoost_For_Anacon ...
- git 重命名 origin
git remote rename origin old-origin git remote add origin https://gitlab.com/wuxianqiang/my-project. ...
- Got error 28 from storage engine 解决方法
早上一来,jira点击任何页面都会报错,首先查看服务器的日志 然后服务器首先看了磁盘,果不其然,是根目录的磁盘满了, 然后就一层一层找占用最大的文件 命令: cd /usr du -sh * 找到了文 ...
- 堆(heap)与栈(stack)
编程语言书籍中经常解释: 值类型被创建在栈上,引用类型被创建在堆上. 构造函数,原型之类的算是引用类型吗? 5种基本数据类型有Undefined.Null.Boolean.Number 和 Str ...
- Python概念(八)字符串格式化:%和.format
https://www.cnblogs.com/nulige/p/6115793.html
- pwnable.kr fb
fb-1 pt 连接到服务器,发现 有三个文件,fd脚本,fd.c脚本的源程序,flag是要看的东西,无权限 来我们分析一下源码 如果只传进去一个值,print” pass argv[1] a num ...
- ASP.NET MVC - 安全、身份认证、角色授权和ASP.NET Identity
ASP.NET MVC - 安全.身份认证.角色授权和ASP.NET Identity ASP.NET MVC内置的认证特性 AuthorizeAttribute特性(System.Web.Mvc)( ...
- MySql cmd下的学习笔记 —— 有关select的操作(max, min等常见函数)
先把之前建的goods表找到 找到最贵的本店价(max) 找到最便宜的本店价(min) 查出一共还有多少商品(count) 查看商品价的平均价(avg) 查看本店有多少种商品 当count(*)时 输 ...
- springboot整合JSP以及发布项目到独立的tomcat中与打成jar包使用
之前研究了springboot整合freemarker与thymeleaf的使用.也研究了springboot发布到独立的tomcat的使用以及使用自带的tomcat打成jar包的使用,下面研究集成J ...