알고리즘 : 달리기 경주
#include <string>
#include <vector>
#include <map>
using namespace std;
vector<string> solution(vector<string> players, vector<string> callings)
{
vector<string> answer;
std::map<int, string> mapRank;
std::map<string, int> mapPlayer;
for (int i = 0; i < players.size(); ++i)
{
mapPlayer[players[i]] = i;
mapRank[i] = players[i];
}
size_t size = callings.size();
for (size_t i = 0; i < size; ++i)
{
int index = mapPlayer[callings[i]];
string Faward = mapRank[index - 1];
swap(mapRank[index], mapRank[index - 1]);
swap(mapPlayer[callings[i]], mapPlayer[Faward]);
}
for(auto p : mapRank)
{
answer.push_back(p.second);
}
return answer;
}
Moding