본문 바로가기

코딩 테스트

백준 10814

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool Compare(pair<int, pair<int, string>> a, pair<int, pair<int, string>> b)
{
	if (a.first == b.first)
	{
		return a.second.first < b.second.first;
	}
	else
	{
		return a.first < b.first;
	}


}

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	vector<pair<int, pair<int, string>>> in;

	int input = 0;

	cin >> input;

	for (int i = 0; i < input; ++i)
	{
		pair<int, pair<int, string>> a;
		cin >> a.first >> a.second.second;
		a.second.first = i;
		in.push_back(a);
	}
	sort(in.begin(), in.end(), Compare);

	for (vector<pair<int, pair<int, string>>>::iterator iter = in.begin(); iter != in.end(); ++iter)
	{
		cout << (*iter).first << " " << (*iter).second.second << "\n";
	}






	return 0;
}

'코딩 테스트' 카테고리의 다른 글

백준 10951  (0) 2023.06.26
백준 1152  (0) 2023.06.24
백준 1018 체스판  (0) 2023.06.22
백준 10866  (0) 2023.06.20
백준 1920  (0) 2023.06.20