프로그래머스 <달리기경주>

마스터피스·2024년 2월 1일

코딩테스트 문제

목록 보기
10/21
post-thumbnail
#include <string>
#include <vector>
#include <map>

using namespace std;

vector<string> solution(vector<string> players, vector<string> callings) {
    vector<string> answer;
    map<int, string> m1;
    map<string, int> m2;
    for(int i = 0 ; i < players.size(); i++){
        m1[i] = players[i];
        m2[players[i]] = i;
    }
    for (int i = 0; i < callings.size(); i++){
        int cur_idx = m2[callings[i]];
        string change = m1[cur_idx -1];
        m1[cur_idx -1] = callings[i];
        m1[cur_idx] = change;
        m2[callings[i]] = cur_idx -1;
        m2[change] = cur_idx;
        }
    for(auto c : m1) answer.push_back(c.second);
    return answer;
}
profile
코딩 일지

0개의 댓글