반응형
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 |
Tags
- OFFSET
- 성적평가
- BOJ
- dfs
- compose
- @P0
- softeer
- Docker
- 매개변수탐색
- msSQL
- 6987
- 이분탐색
- upper_bound
- 백준
- 처우산정
- incr
- 백트래킹
- 기술면접
- Kafka
- 물채우기
- 연결요소
- 경력
- 13908
- 소프티어
- 파라메트릭
- 오퍼레터
- 처우협의
- boj #19237 #어른 상어
- 퇴사통보
- BFS
Archives
- Today
- Total
기술 블로그
count(), count_if() 본문
728x90
반응형
http://www.cplusplus.com/reference/algorithm/count/
count() : 배열, 벡터 등 원하는 값(원소)의 개수를 찾아줌. string, char, int 모두 가능하다.
count_if() : 조건에 맞는 배열, 벡터 등 원하는 값(원소)의 개수를 찾아줌. string, char, int 모두 가능하다.
count(시작점, 끝점, 찾을 값);
count_if(시작점, 끝점, bool 함수);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <bits/stdc++.h> using namespace std; bool isEven(int i) { return (i % 2 == 0 ); } int main(void) { vector<int> v = { 1, 2, 3, 4, 5, 2, 3, 4, 3, 9, 12, 3 }; printf("%d\n", count(v.begin(), v.end(), 3)); printf("%d\n", count_if(v.begin(), v.end(), isEven)); vector<string> s = { "ABC", "DEF", "ABC", "EFG" }; printf("%d\n", count(s.begin(), s.end(), "ABC")); return 0; } | cs |
728x90
반응형
'C++ STL' 카테고리의 다른 글
vector struct 구조체 정렬(3개 이상) (0) | 2019.06.29 |
---|---|
search() (0) | 2019.05.20 |
equal() (0) | 2019.05.20 |
is_sorted() (0) | 2019.05.10 |
lower_bound(), upper_bound() (0) | 2019.05.05 |