`
yuanlanjun
  • 浏览: 1176867 次
文章分类
社区版块
存档分类
最新评论

accumulate,inner_product,partial_sum,adjacent_difference

 
阅读更多

直接代码如下:

//数值计算
//accumulate
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<functional>
#include<vector>
using namespace std;
int main(){
	int a[]={1,2,3,4,5,6,7,8,9,10};
	vector<int>v(a,a+10);
	int max=accumulate(v.begin(),v.end(),0);
	cout<<max<<endl;
	int jianyibai=accumulate(v.begin(),v.begin()+4,1,multiplies<int>());
	cout<<jianyibai<<endl;
	system("pause");
	return 0;
}
//inner_product
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int a[]={1,2,3,4,5,6,7,8,7,9,10};
	vector<int>v(a,a+10);
	vector<int>vv(a,a+10);
	int max=inner_product(v.begin(),v.end(),vv.begin(),1);
	cout<<max<<endl;
	
	cout<<inner_product(v.begin(),v.begin()+5,vv.begin(),1,multiplies<int>(),plus<int>());
	cout<<endl;
	system("pause");
	return 0;
}
//partial_sum
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
int main(){
	int a[]={1,2,3,4,5,6};
	vector<int>v(a,a+6);
	partial_sum(v.begin(),v.end(),ostream_iterator<int>(cout," "));
	cout<<endl;

	partial_sum(v.begin(),v.end(),ostream_iterator<int>(cout," "),multiplies<int>());
	cout<<endl;
	system("pause");
	return 0;
}
//adjacent_difference
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
int main(){
	int a[]={1,2,3,4,5,6,7,8,9,10};
	vector<int>v(a,a+10);
	adjacent_difference(v.begin(),v.end(),ostream_iterator<int>(cout," "));
	cout<<endl;

	adjacent_difference(v.begin(),v.end(),ostream_iterator<int>(cout," "),plus<int>());
	cout<<endl;
	system("pause");
	return 0;
}


分享到:
评论

相关推荐

    STL数值算法源码

    参考自侯捷先生的《STL源码剖析》,C++ STL 的数值算法(Numeric algorithms)是一组对容器元素进行数值计算的模板函数,包括容器元素求和 accumulate 、两...partial_sum 、容器每对相邻元素的差adjacent_difference。

    30-seconds-of-cpp:30秒的C ++(C ++中的STL)。 在此处阅读有关30C ++的更多信息:backhand_index_pointing_right:

    adjacent_difference adjacent_find all_of any_of binary_search clamp copy copy_backward copy_if copy_n count count_if equal equal_range fill fill_n find find_first_of find_if find_...

    STL源码剖析.pdg

    6.3.4 inner_product 301 6.3.5 partial_sum 303 6.3.6 power 304 6.3.7 itoa 305 6.4 基本算法 [stl_algobase.h] 305 6.4.1 运用实例 305 6.4.2 equal 307 fill 308 fill_n 308 iter_swap 309 ...

    C++ STL 开发技术导引(第6章)

    24.3 两序列元素内积inner_product 414 24.4 部分元素求和partial_sum 415 24.5 相邻元素求差adjacent_difference 417 24.6 n次方计算power 419 24.7 本章小结 421 第五篇 C++ STL迭代器技术 第25章 ...

    C++ STL开发技术导引(第5章)

    24.3 两序列元素内积inner_product 414 24.4 部分元素求和partial_sum 415 24.5 相邻元素求差adjacent_difference 417 24.6 n次方计算power 419 24.7 本章小结 421 第五篇 C++ STL迭代器技术 第25章 ...

    C++ STL开发技术导引(第3章)

    24.3 两序列元素内积inner_product 414 24.4 部分元素求和partial_sum 415 24.5 相邻元素求差adjacent_difference 417 24.6 n次方计算power 419 24.7 本章小结 421 第五篇 C++ STL迭代器技术 第25章 ...

    STL 源码剖析(侯捷先生译著)

    6.3.4 inner_product 301 6.3.5 partial_sum 303 6.3.6 power 304 6.3.7 itoa 305 6.4 基本算法 [stl_algobase.h] 305 6.4.1 运用实例 305 6.4.2 equal 307 fill 308 fill_n 308 iter_swap 309 ...

    C++并发与多线程-运行时选择线程数量

    使用std::thread::hardware_concurrency() 来获得当前系统可以真正并发的线程数量,和cpu的核心数有关。 #include #include #include #include #include #include std::mutex g_lock;... ~accumulate_block() {

    accumulate函数

    accumulate函数

    PyPI 官网下载 | py_accumulate-0.0.1rc0-py3-none-any.whl

    资源来自pypi官网。 资源全名:py_accumulate-0.0.1rc0-py3-none-any.whl

    mzkmzk#WEB_Accumulate#刷新4041

    刷新404问题在使用react-router之后我们实际只有一个html,一般命名为index.html如果我们首先进入index.html 然后调整到其他在r

    pandas_accumulate-0.1.0.tar.gz

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、...

    mzkmzk#WEB_Accumulate#前端监控1

    入门了解1. 性能方面2. 异常方面基本可以采取的措施有可以捕抓语法错误特点无法不抓到语法错误,智能捕抓运行时错误2.4 JS的跨域问题其他类似产品http:/

    mzkmzk#WEB_Accumulate#path模块1

    Path模块获取文件路径 path.dirname(path)获取文件后缀 path.extname(path)获取文件基本名称 path.basename(p

    OBKoro1#web_accumulate#推箱子1

    1. 渲染地图 2. 捕获键盘事件,判断是否可以移动 3.胜利判断:

    Anewapproachtosimulatepeatacc

    Anewapproachtosimulatepeataccumulation,degradationandstabilityinagloballandsurfacescheme(JULESvn5.8_accumulate_共25页.pdf.zip

    OBKoro1#web_accumulate#55题跳远游戏1

    55 题跳远游戏题目链接难度:中等思路分析:贪心代码:贪心var canJump = function(nums) {// 下一步的最远距离let last_c

    OBKoro1#web_accumulate#Eslint自动修复格式错误1

    1.安装VsCode的EsLint和vetur插件 2.为项目安装EsLint包: 3.在项目的根目录下添加.eslintrc.js 4.首选项设置:

    pandas_accumulate-0.1.0-py3-none-any.whl

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、...

Global site tag (gtag.js) - Google Analytics