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 ...
随机推荐
- 进程池爬取并存入mongodb
设置进程池爬取拉钩网: # coding = utf- import json import pymongo import pandas as pd import requests from lxml ...
- MeEclipse搭建SSH框架之———大体框架
必备:MyEclipse软件,SSH需要的jar包,数据库,连接数据库的驱动jar包 先搭建大体框架,再加别的东西,要不都不知道哪里错了 一.新建web项目 MyEclipse左边右键--->N ...
- ionic 照相机 Camera
1.官网: https://ionicframework.com/docs/native/camera/#DestinationType 2.引入插件 $ ionic cordova plugin a ...
- 20165337岳源 第四次实验 Android开发
1.实验要求: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)>第二十四章 参考http://www.cnblogs.com ...
- 求两个排序数组中位数 C++
题目描述: 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 . 请找出这两个有序数组的中位数.要求算法的时间复杂度为 O(log (m+n)) . 你可以假设 nums1 和 nu ...
- oracle查看未提交事务
SELECT s.sid, s.serial#, s.event, a.sql_text, a.sql_fulltext, s.username, s.status, s.machine, s.ter ...
- macbook install mysql
安装Homebrew,详细步骤参见Homebrew官网. brew doctor确认brew在正常工作. brew update更新包. brew install mysql 安装mysql.log如 ...
- platform模块
import platform ''' python中,platform模块给我们提供了很多方法去获取操作系统的信息 如: import platform platform.platform() #获 ...
- Python3学习笔记02-基础语法
默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串 ' # -*- coding:cp-1252 -*-' 也可以指定其他编码,以上用cp-1252字符 ...
- 带你玩转Visual Studio——带你了解VC++各种类型的工程
原文地址:http://blog.csdn.net/luoweifu/article/details/48816605 上一篇文章带你玩转Visual Studio——带你新建一个工程一文中提到新建一 ...