목록알고리즘/C++ 개념 (10)
Study

● set - 중복값을 허용하지 않는 컨테이너 - default 정렬기준은 less(오름차순) - set 변수이름; 예) set s; ● 멤버함수 set::iterator iter 를 선언해줘야함 1. s.begin() : 맨 첫번째 원소를 가리키는 iterator를 리턴 s.end() : 맨 마지막 원소의 다음을 가리키는 iterator를 리턴 예제) 2. s.clear() : 모든 원소를 제거 3. s.empty() : set s가 비어있는지 확인 4. s.erase(iter) - iter가 가리키는 원소를 제거 - 제거한 후 제거한 원소의 다음 원소를 가리키는 iterator를 리턴 s.erase(start, end) : [start, end) 범위의 원소를 모두 제거 예제) 5. s.size() ..
-원소 추가 ● push(element) : 가장 끝에 원소를 삽입 -원소 삭제 ● pop() : 가장 첫번째 원소를 제거 -큐의 첫 번째 원소 반환 ● front() -큐의 제일 끝에 있는 원소 반환 ● back() -참고 사이트 std::queue - cppreference.com template class queue; The std::queue class is a container adapter that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure. The class templ..

#include InputIterator find(InputIterator first, InputIterator last, const T& val); ·리턴 값 : first부터 last전까지 [first,last) 의 원소들 중 val과 일치하는 첫 번째 원소를 가리키는 반복자 리턴, 만약 일치하는 원소를 찾지 못할 경우 last를 리턴 The function uses operator == to compare the individual elements to val. 예제) 실행 결과) -참고 사이트 www.cplusplus.com/reference/algorithm/find/

● next_permutation - #include 헤더에 포함 - 기본 형식 bool next_permutation(BidirectionalIterator first, BidirectionalIterator last); - 순열: 서로 다른 n개 중에 r개를 선택하는 경우의 수 (순서 상관 있음) - [first, last) 범위의 요소를 사전 순으로 더 큰 순열로 다시 정렬 - 더 큰 순열로 객체를 재 배열 할 수있는 경우 true 반환 - Example - 실행 결과 -참고 사이트 coding-factory.tistory.com/606 twpower.github.io/82-next_permutation-and-prev_permutation www.cplusplus.com/reference/algo..

● unique함수 - #include 헤더 파일에 존재 - vector 배열에서 중복되지 않는 원소들을 앞에서부터 채워나가는 함수 - 중복되지 않는 원소들을 앞에서부터 채워나가기때문에 남은 뒷부분은 그대로 vector원소값이 존재함 - unique함수의 리턴값은 겹치지 않는 원소들이 끝나고 첫번째 쓰레기 원소가 나오는 곳의 위치이다. ● erase함수 - v.erase(unique(v.begin(),v.end()), v.end()); - 위 예시 1 2 4 5 4 5 에서 unique(v.begin(),v.end()) 리턴값으로 나온 4부터 벡터의 마지막 원소까지 삭제함 - 참고 사이트 sanghyu.tistory.com/78 sangwoo0727.github.io/c++/Cplus-unique/
문자를 다루는 함수는 헤더 파일에 존재함 toupper(), isalpha(), isdigit() + isalpha() 내용 추가 알파벳 대문자 "A-Z"는 1을 반환 알파벳 소문자 'a-z"는 2를 반환 알파벳이 아닌것은 0을 반환 isalpha(), isdigit()사용 예) string a = "hello"; for(int i=0; i

template struct pair; 데이터의 쌍을 표현할 때 사용 사용법) pair p; p.first //p의 첫 번째 인자 반환 p.second //p의 두 번째 인자 반환 make_pair(변수 1, 변수 2) //변수 1과 변수 2가 들어간 pair를 만들어 준다 실행 결과) - pair www.cplusplus.com/reference/utility/pair/ blockdmask.tistory.com/64 securityholic.tistory.com/195
string : c++표준 라이브러리에서 제공하는 클래스로서, 문자열을 객체로 다룬다. string 클래스 사용시 다음 코드 필요 #include using namespace std; · 공백을 포함하는 문자열 입력받기 헤더 파일에 선언된 getline() 전역함수 이용 예) string name; getline(cin, name, '\n'); //'\n'을 만날 때까지 키보드(cin)으로 부터 문자열을 읽어 name에 저장 첫 번째 인자 : cin 두 번째 인자 : string 객체 세 번째 인자 : 문자열의 마지막을 표시하는 구분 문자 pos : 문자열 내의 문자 위치, 0부터 시작 멤버 함수 설명 string& append(string& str) 문자열 뒤에 str 추가 예) string str; ..