⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alg33.c

📁 C++Primer中文版 第三版 深入系列 Primer 第三版 著 中中文文版版潘爱民张丽译 Addison-Wesley 中国电力出版社 www.infopower.com.cn S
💻 C
字号:
#include <numeric>
#include <vector>
#include <iostream.h>

/*
 * generates:
   elements: 1 3 4 5 7 8 9 
   partial sum of elements:
   1 4 8 13 20 28 37 
   partial sum of elements using times<int>():
   1 3 12 60 420 3360 30240 
*/
	
int main()
{
	const int ia_size = 7;
	int ia[ ia_size ] = { 1, 3, 4, 5, 7, 8, 9 };
	int ia_res[ ia_size ];

	ostream_iterator< int  > outfile( cout, " "  );
	vector< int, allocator > vec( ia, ia+ia_size );
	vector< int, allocator > vec_res( vec.size() );

	cout << "elements: ";
        copy( ia, ia+ia_size, outfile ); cout << endl;


	cout << "partial sum of elements:\n";
	partial_sum( ia, ia+ia_size, ia_res ); 
	copy( ia_res, ia_res+ia_size, outfile ); cout << endl;
		

	cout << "partial sum of elements using times<int>():\n";
	partial_sum( vec.begin(), vec.end(), vec_res.begin(), times<int>() );
	copy( vec_res.begin(), vec_res.end(), outfile ); cout << endl;
		
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -