其他分享
首页 > 其他分享> > adjacent_find

adjacent_find

作者:互联网

adjacent_find用于在指定范围内查找1个连续出现2次的元素。

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<int> v{ 1,2,2,4,5,2,3,4,7,8,9,1,7,7,3,4 };

    auto it = adjacent_find(v.begin(), v.end());
    if (it != v.end())
    {
        cout << "v[" << it - v.begin() << "]=" << *it << endl;
        it = adjacent_find(++it, v.end());
        {
            cout << "v[" << it - v.begin() << "]=" << *it << endl;
        }
    }

    return 0;
}

输出结果:

v[1]=2
v[12]=7

标签:end,cout,int,adjacent,include,find
来源: https://blog.csdn.net/atinybirdinit/article/details/119353059