首页 技术 正文
技术 2022年11月16日
0 收藏 919 点赞 5,068 浏览 2252 个字

当心文件 I/O 有错误。

 #include <iostream>
#include <iostream>
#include <numeric>
#include <vector>
#include <list>
#include <set> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; //利用类模板生成类实例
typedef vector < int > IntArray;
typedef list <int> LISTINT;
typedef set<int> SET_INT;
int add(int a, int b) {
return a+b;
}
//在main()函数中测试accumulate算法
int main(int argc, char** argv) {
{
//--------------------------------------------
// accumulate算法对于普通数组的计算
//---------------------------------------------
int x[]={,,,,}; cout<<"x[]:";
for (int i=;i<;i++)
cout<<x[i]<<" ";
cout<<endl;
cout<<"accumulate(x,x+5,0)=";
cout<<accumulate(x,x+,)<<endl;
int val=;
cout<<"val="<<val<<endl;
cout<<"accumulate(x,x+5,val)=";
cout<<accumulate(x,x+,val)<<endl;
//--------------------------------------------
// accumulate算法对于vector容器的计算
//---------------------------------------------
//声明intvector容器和迭代器ii
IntArray intvector;
IntArray::iterator ii; //向intvector容器中插入元素
for (int i=; i<=; i++) {
intvector.push_back(i);
}; //显示intvector容器中的元素值和累加结果
cout << "intvector: "<<endl;
for (ii=intvector.begin();ii !=intvector.end();++ii)
cout<<(*ii)<<" ";
cout<<endl;
cout<<"accumulate(intvector.begin(),intvector.end(),0)=";
cout<<accumulate(intvector.begin(),intvector.end(),)<<endl;
//--------------------------------------------
// accumulate算法对于list容器的计算
//---------------------------------------------
//声明list容器对象和迭代器
LISTINT::iterator iL;
LISTINT list1; //向list1容器对象中插入元素并显示
list1.push_front();
list1.push_front();
list1.push_front();
list1.push_back();
list1.push_back(); //显示list1容器的元素值和累加结果
cout << "list1: "<<endl;
for (iL=list1.begin();iL !=list1.end();++iL)
cout<<(*iL)<<" ";
cout<<endl;
cout<<"accumulate(list1.begin(),list1.end(),0)=";
cout<<accumulate(list1.begin(),list1.end(),)<<endl;
//--------------------------------------------
// accumulate算法对于set容器的计算
//---------------------------------------------
//声明set容器对象和迭代器
SET_INT set1;
SET_INT::iterator si; //向set1容器中插入元素
set1.insert();
set1.insert();
set1.insert();
set1.insert();
set1.insert(); //显示set1容器的元素值和累加结果
cout <<"set1: "<<endl;
for (si=set1.begin();si !=set1.end();++si)
cout<<(*si)<<" ";
cout<<endl;
cout<<"accumulate(set1.begin(),set1.end(),0)=";
cout<<accumulate(set1.begin(),set1.end(),)<<endl;
cout<<"accumulate(set1.begin(),set1.end(),100)=";
cout<<accumulate(set1.begin(),set1.end(),)<<endl;
return ;
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290