vector 요소의 중복 값 제거
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
1. 정렬을 한다.
2. 연속된 숫자를 쓰레기 값 즉 벡터의 뒷부분으로 보낸다. (unique)
3. 중복된 요소가 모여있는 부분들을 삭제한다.(erase)
vector 최댓값 최솟값 인덱스 구하기
int max=*max_element(v.begin(),v.end());
int min=*min_element(v.begin(),v.end());
int max_index=max_element(v.begin(),v.end())-v.begin();
int min_index=min_element(v.begin(),v.end())-v.begin();
'Algorithm > 코테정리' 카테고리의 다른 글
[코테정리] C++ 소수점 N자리 출력하기 (0) | 2021.09.09 |
---|---|
[코테정리] C++ 순열, 조합구현(재귀) (0) | 2021.06.07 |
[코테정리] C++ 윤년, 윤달, 요일 출력하기 (0) | 2021.06.07 |
[코테정리] C++ N자리 2진수 만들기 및 2진수 변환 (0) | 2021.06.07 |
[코테정리] C++ 정렬문제 (0) | 2021.06.05 |