일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Counting cells in a blob
- 파이썬 포렌식
- Sequential Search
- 파이썬머신러닝완벽가이드
- flask
- Numpy
- recursion
- matrixElementsSum
- Python
- almostIncreasingSequence
- cpp
- 2015 봄학기 알고리즘
- 수 정렬하기
- til
- C++
- shapeArea
- 2750
- baekjun
- markdown
- centuryFromYear
- Daily Commit
- 피보나치 수
- data_structure
- codesignal
- 백준
- 10953
- codesingal
- collections.deque
- All Longest Strings
- adjacentElementsProduct
Archives
- Today
- Total
Introfor
[C++] Pair, Vector STL 본문
STL
표준 템플릿 라이브러리(Standard Template Library)
C++에서 필요한 자료구조와 알고리즘을 Template로 제공하는 라이브러리
구성
Container, Iterator, functor, Algorith
Pair and Vector
Pair
#include <utility> 헤더 파일을 추가해주거나 <vector>또는 <algorithm> 헤더를 추가해줍니다.
Pair는 두 쌍의 자료형을 묶어서 사용하는 것으로 pair<int, int>형식으로 작성한다.
#include <iostream>
#include <vector>
using namespace std;
pair<int, int> p;
int main(){
// how to put in pair
// p.first = 1;
// p.second = 5;
p = make_pair(1,5);
printf("%d %d\n", p.first, p.second);
return 0;
}
pair 값 설정은 두 가지 방법으로
-
first와 second로 접근해서 직접 값을 넣기
-
make_pair(value, value)
Vector
배열을 동적으로 사용하는 것으로 쉽게 변하는 배열이라고 생각하면 된다.
#include <vector>
vector에서 멤버함수 여러 가지 있다.
#include <iostream>
#include <vector>
using namespace std;
vector<pair<int, int>> v(2);
int main(){
v[0] = make_pair(2,6);
printf("%d %d\n", v[0].first, v[0].second);
printf("%zu \n",v.size());
v.resize(3);
printf("%zu \n",v.size());
return 0;
}
'Doing > C&C++' 카테고리의 다른 글
[Algorithm] sequential Search (0) | 2020.07.01 |
---|---|
[C++] Reference (0) | 2020.06.29 |
요셉의 환형 문제 (0) | 2017.10.10 |
행렬 경로 찾기 (0) | 2017.10.04 |
조약돌 놓기 (0) | 2017.10.02 |
Comments