300x250
알고리즘 문제를 풀다보면 vector에 값을 2개씩 넣고싶을때가 생기는데여 map을 써도 되겠지만 벡터가 좀더 친숙할 때가 있더라구여
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <pair<int, int>> vec;
int num1, num2;
int cnt;
cin >> cnt;
for (int i = 0; i < cnt; i++)
{
cin >> num1;
cin >> num2;
vec.push_back(make_pair(num1, num2));
}
for (int i = 0; i < cnt; i++)
{
cout << "vec[" << i << "].first : " << vec[i].first << endl;
cout << "vec[" << i << "].second : " << vec[i].second << endl;
}
}
300x250