sicily 1775. Simple Sort

1699 단어 pair
요즘 약 해 졌 는데....................................................
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

vector<pair<int, int> > priority; // idNum, priority;

int entryNum;
int colNum;
int queryNum;

struct entry
{
	int num;
	int number[15];
};


bool compPriority(const pair<int, int>& p1, const pair<int, int>& p2)
{
	return p1.second < p2.second;
}

bool compEntry(const entry& e1, const entry& e2)
{
	for (int i = 0; i < colNum; i++)
	{
		int curPos = priority[i].first;
		if (e1.number[curPos] < e2.number[curPos])
			return true;
		else if (e1.number[curPos] > e2.number[curPos])
			return false;
	}
	return e1.num < e2.num;
}


int main()
{
	int testCase;
		
	cin >> testCase;

	while (testCase--) 
	{
		entry entries[150];

		cin >> entryNum >> colNum;

		for (int i = 0; i < entryNum; i++)
		{
			entry e;
			e.num = i;
			for (int j = 0; j < colNum; j++)
			{
				cin >> e.number[j];
			}
			entries[i] = e;
		}

		cin >> queryNum;
		int queryCount = 0;

		while (queryCount < queryNum)
		{
			int p;
			for (int i = 0; i < colNum; i++)
			{
				cin >> p;
				priority.push_back(make_pair(i, p));
			}
			sort(priority.begin(), priority.end(), compPriority);


			sort(entries, entries + entryNum, compEntry);

			
			for (int i = 0; i < entryNum; i++)
			{
				if (i == 0)
					cout << entries[i].num;
				else
					cout << " " << entries[i].num; 
			}
			cout << endl;

			priority.clear();
			queryCount++;
		}

	}

	return 0;
}

좋은 웹페이지 즐겨찾기