본문 바로가기
프로그래밍 기록/stl

adjacent_find

by hominic 2023. 12. 9.
728x90
반응형

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

반응형

 

 

adjacent_find

void main()
{
int ari[]={1,9,3,6,7,5,5,8,1,4};
vector<int> vi(&ari[0],&ari[9]);

vector<int>::iterator it;
it=adjacent_find(vi.begin(),vi.end());
if (it != vi.end()) {
printf("두 요소가 인접한 값은 %d입니다.\n",*it);
}
}

 

 

 

adjacent_find2 

bool doublespace(char a, char b)
{
return (a==' ' && b== ' ');
}

void main()
{
const char *str="기다림은  만남을 목적으로 하지 않아도  좋다.";

const char *p,*pend=&str[strlen(str)];
for (p=str;;p++) {
p=adjacent_find(p,pend,doublespace);
if (p==pend) break;
cout << p-str << "위치에 이중 공백이 있습니다." << endl;
}
}
728x90
반응형

'프로그래밍 기록 > stl' 카테고리의 다른 글

for_each  (0) 2023.12.09
search  (0) 2023.12.09
shuffle  (0) 2023.12.09
reverse  (0) 2023.12.09
sort  (0) 2023.12.09

댓글