#include <iostream>     // cout
#include <algorithm>    // adjacent_find
#include <vector>       // vector
using namespace std;
bool myfunction (int i, int j) {
    return (i==j);
}

int main () {
    int myints[] = {5,5,20,30,30,20,10,10,20};
    vector<int> myvector (myints,myints+9);
    vector<int>::iterator it;
    
    // using default comparison:
    it = adjacent_find (myvector.begin(), myvector.end());
    
    if (it!=myvector.end())
        cout << "the first pair of repeated elements are: " << *it << '\n';
    
    //using predicate comparison:
    it = adjacent_find (++it, myvector.end(), myfunction);
    
    if (it!=myvector.end())
        cout << "the second pair of repeated elements are: " << *it << '\n';
    
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2022-01-09
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案