반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 소프티어
- 백준
- 오퍼레터
- 성적평가
- msSQL
- 퇴사통보
- compose
- 연결요소
- incr
- upper_bound
- 이분탐색
- 백트래킹
- 처우산정
- 처우협의
- 물채우기
- 13908
- @P0
- 6987
- OFFSET
- BFS
- 매개변수탐색
- 파라메트릭
- Kafka
- softeer
- Docker
- boj #19237 #어른 상어
- BOJ
- 기술면접
- 경력
- dfs
Archives
- Today
- Total
기술 블로그
문자열 자체의 find와 C++ STL인 find 본문
728x90
반응형
주석 참고
1 2 3 4 5 6 7 8 9 10 11 12 | 문자열 asdioeabcedsddio안에 d가 2번 째에 존재합니다. 문자열 asdioeabcedsddio안에 z가 존재하지 않습니다. 2 -1 13 1 2 | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <bits/stdc++.h> using namespace std; void string_check(string s, char c) { // C++ STL find는 '문자'만 적용된다. '문자열'은 문자열(여기서는 s)의 find를 이용해야한다. if (find(s.begin(), s.end(), c) != s.end()) { cout << "문자열 " << s << "안에 " << c << "가 " << find(s.begin(), s.end(), c) - s.begin() << "번 째에 존재합니다.\n"; } else { cout << "문자열 " << s << "안에 " << c << "가 존재하지 않습니다.\n"; } printf("\n"); } int main(void) { //cin.tie(0); string s = "asdioeabcedsddio"; string_check(s, 'd'); string_check(s, 'z'); int idx = s.find("dio"); // 문자열 s안에서 "dio"를 찾는다. 없으면 -1을 반환함. printf("%d\n\n", idx); idx = s.find("dioz"); // 문자열 s안에서 "dio"를 찾는다. 없으면 -1을 반환함. printf("%d\n\n", idx); // 참고로 문자열은 0부터 시작한다.(인덱스 번호) idx = s.find("dio", 3); // 문자열 s의 3번째 원소부터 "dio"를 찾는다. 없으면 -1을 반환함. printf("%d\n\n", idx); // 보너스 vector<int> v = { 2,3,4,4 }; cout << find(v.begin(), v.end(), 3) - v.begin() << '\n'; cout << count(v.begin(), v.end(), 4) << '\n'; return 0; } | cs |
728x90
반응형
'C++ STL' 카테고리의 다른 글
vector struct 구조체 정렬(3개 이상) (0) | 2019.06.29 |
---|---|
search() (0) | 2019.05.20 |
count(), count_if() (0) | 2019.05.20 |
equal() (0) | 2019.05.20 |
is_sorted() (0) | 2019.05.10 |