cb31a_c++_STL_算法_查找算法_(4)find_first_of
find_first_of(b,e,sb,se),sb,second begin, se,second end();
find_first_of(b,e,sb,se,bp),bp--谓词,就是一个函数,或者函数对象,返回一个bool

使用逆向迭代器,实现string类的rfind.找最后一个。reverse_find=rfind
没有find_last_of算法,string类的成员函数有find_last_of

find()
find_if()
search_in()
serarch()
find_end()
find_first_of()
adjacent_find()
txwtech@163.com

 /*cb31a_c++_STL_算法_查找算法_(4)find_first_of
find_first_of(b,e,sb,se),sb,second begin, se,second end();
find_first_of(b,e,sb,se,bp),bp--谓词,就是一个函数,或者函数对象,返回一个bool 使用逆向迭代器,实现string类的rfind.找最后一个。reverse_find=rfind
没有find_last_of算法,string类的成员函数有find_last_of find()
find_if()
search_in()
serarch()
find_end()
find_first_of()
adjacent_find()
txwtech@163.com
*/ #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string> using namespace std; int main()
{
vector<int> ivec;
list<int> searchList;
for (int i = ; i <= ; ++i)
{
ivec.push_back(i);
}
for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
cout << *iter << ' ';
cout << endl;
searchList.push_back();
searchList.push_back();
searchList.push_back(); cout << "ivec里面找,3,6,9" << endl;
vector<int>::iterator pos;
pos=find_first_of(ivec.begin(), ivec.end(), searchList.begin(), searchList.end());
if (pos != ivec.end())
cout << "找到了,位置是:" << distance(ivec.begin(), pos) + << endl;
else
cout << "没找到" << endl; vector<int>::reverse_iterator rpos;
// rpos.base(),转换成正向迭代器,就不需要加1了
rpos= find_first_of(ivec.rbegin(), ivec.rend(), searchList.begin(), searchList.end());
if (rpos != ivec.rend())
cout << "逆向迭代器找到了,位置是:" << distance(ivec.begin(), rpos.base()) << endl;
else
cout << "没找到" << endl; string numerics("");
string name("ra82d3k"); cout << "name里面找numerics的内容" << endl;
string::size_type posn= name.find_first_of(numerics);//顺序查找
if (posn != string::npos)
cout << "posn不等于npos,npos表示结束位置,已经扎到了,下标:" << posn << endl;
else
cout << "没找到" << endl; posn = name.find_last_of(numerics);//逆向查找
if (posn != string::npos)
cout << "逆向查找,最后一位开始找,已经扎到了,下标:" << posn << endl;
else
cout << "没找到" << endl; return ;
}

cb31a_c++_STL_算法_查找算法_(4)find_first_of的更多相关文章

  1. cb34a_c++_STL_算法_查找算法_(7)_lower_bound

    cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...

  2. cb33a_c++_STL_算法_查找算法_(6)binary_search_includes

    cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e ...

  3. cb32a_c++_STL_算法_查找算法_(5)adjacent_find

    cb32a_c++_STL_算法_查找算法_(5)adjacent_findadjacent_find(b,e),b,begin(),e,end()adjacent_find(b,e,p),p-par ...

  4. cb30a_c++_STL_算法_查找算法_(3)search_find_end

    cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...

  5. cb29a_c++_STL_算法_查找算法_(2)search_n

    cb29a_c++_STL_算法_查找算法_(2)search_n//比如:连续查找连续的n个8search_n(b,e,c,v),迭代器b,begin(),e,end().连续的c个vpos=sea ...

  6. cb28a_c++_STL_算法_查找算法_(1)find_find_if

    cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...

  7. STL_算法_查找算法(lower_bound、upper_bound、equal_range)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n)))    已序区间查找算法 lower_bound()        //找第一个符合的 ...

  8. STL_算法_查找算法(find、find_if)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...

  9. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

随机推荐

  1. [JavaWeb基础] 002.JSP和SERVLET初级入门

    上一篇中,我介绍了javaweb项目的创建和Tomcat的搭建和部署,接下来我们要在上一篇的基础上去讲解一下简单的jsp和servlet交互,做出一个简单的登陆功能页面.该例子主要讲解了从页面请求道后 ...

  2. JSP指令 & 中文乱码问题

    1. JSP 指令: JSP指令(directive)是为JSP引擎而设计的,     它们并不直接产生任何可见输出, 而只是告诉引擎如何处理JSP页面中的其余部分. 2. 在JSP 2.0中,定义了 ...

  3. 【转】网页的title左边的小图片怎么添加

    首先,代码中的title标签里是不能加图片的.但是浏览器标提栏前面是可以加一个小图标的. 解决方案:第一步,做一个16 X 16像素的ico格式的图标.具体操作方法是,先在Photoshop中做一个透 ...

  4. & Google前沿的AMP技术

    首先要知道什么是AMP以至于为什么要选择AMP? AMP他并不是一门新技术,他只是一种能够让页面更快打开的一种办法.之所以用他是因为AMP能够带来SEO排名优化.另外Google搜索结果对AMP页面有 ...

  5. php动态安装扩展

    下面以安装phpredis扩展为例 下载扩展源码,解压 [root@localhost ~]# wget phpredis-5.1.1.tar.gz [root@localhost ~]# tar - ...

  6. 跟着阿里学JavaDay06——Java基础语法(四)

    一.方法 方法执行到return语句后,这个方法的执行就结束了,方法可以有返回值,但可以不用这个返回值.方法首先要定义,然后才能调用. public class TestMethod{ public ...

  7. Java实现 蓝桥杯VIP 算法提高 数字黑洞

    算法提高 数字黑洞 时间限制:1.0s 内存限制:256.0MB 问题描述 任意一个四位数,只要它们各个位上的数字是不全相同的,就有这样的规律: 1)将组成该四位数的四个数字由大到小排列,形成由这四个 ...

  8. Java实现 计蒜客 1251 仙岛求药

    仙岛求药 少年李逍遥的婶婶病了,王小虎介绍他去一趟仙灵岛,向仙女姐姐要仙丹救婶婶.叛逆但孝顺的李逍遥闯进了仙灵岛,克服了千险万难来到岛的中心,发现仙药摆在了迷阵的深处.迷阵由 M \times NM× ...

  9. java实现汉诺塔计数

    ** 汉诺塔计数** 汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具. 大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘.大梵天命令婆罗门把圆盘从下 ...

  10. Java基础(十)

    一.XML概述 属性文件是用来描述程序配置,属性文件包含了一组名/值对.属性文件采用的是一种单一的平面层次结构,同时属性文件要求键是唯一的. XML格式能够表达层次结构,并且重复的元素不会被曲解. H ...