Hoon222y

tuple값 가져오기 본문

코딩/사소한 팁

tuple값 가져오기

hoon222y 2017. 6. 3. 14:27

일단 가장 기본적인 #include <tuple> 필수


보통 tuple을 사용하는 이유는 3개의 원소를 저장하기 위해서인데 pair와는 함수사용법이 조금 많이 다르다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <tuple>
typedef long long ll;
#define INF 1e8
 
using namespace std;
 
int main(){
    int a,b,c;
    cin >>>>b>>c;
    priority_queue<tuple<int,int,int>> q;
    q.push(make_tuple(a,b,c));
    
    auto p = q.top();
    q.pop();
    
    int t = get<0>(p);  
    int y = get<1>(p);
    int u = get<2>(p);
    
    cout << t << " " << y << " "<<<< endl;
}
cs


이런식으로 원소 반환을 get<원하는 위치>(튜플의 이름) 이런식으로 반환을 한다. 

추가적인 tuple STL은 http://ko.cppreference.com/w/cpp/utility/tuple 를 참고하자

Comments