algorithm头文件

iset.insert(ivector.begin(),ivector.end())   //复制vector元素到set中,注意这个操作会去重
string str = join(vector," "); //vector拼接成一个string


The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements.
<algorithm> 包括常用的find、count、search、replace、reserve、partition、基于sorting的函数、基于比较的函数(max/min等)、堆函数(Heap)


find函数:#include <algorithm>
InputIterator find ( InputIterator first, InputIterator last, const T& value );


copy函数:#include <algorithm>
OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result );
vector resolving_res;     //利用字符串流把string切分为vector
istringstream iss(outanswer);
copy(istream_iterator(iss), istream_iterator(), back_inserter(resolving_res));


int myints[]={10,20,30,40,50,60,70};  //利用copy函数copy数组to vector
vector<int> myvector;
vector<int>::iterator it;
myvector.resize(7);   // allocate space for 7 elements, Resizes the vector to contain 7 elements.
copy ( myints, myints+7, myvector.begin() );
似乎下面这个也可以完成copy功能:
int myints[] = {10,20,30,5,15};
vector<int> v(myints,myints+5);


replace函数:#include <algorithm>
void replace ( ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value );
int myints[] = { 10, 20, 30, 30, 20, 10, 10, 20 }; 
vector<int> myvector (myints, myints+8); // 10 20 30 30 20 10 10 20 
replace (myvector.begin(), myvector.end(), 20, 99); // 10 99 30 30 99 10 10 99


count函数:#include <algorithm>
count(oriPos.begin(),oriPos.end(),"mm")>1  //count适用于vector,统计vector中有多少个某元素
注意count在set中只返回0或者1;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值