프로그래머스 178871 달리기 경주

1 개요[ | ]

프로그래머스 178871 달리기 경주

2 C++[ | ]

#include <string>
#include <vector>
#include <map>

using namespace std;

vector<string> solution(vector<string> players, vector<string> callings) {
    map<string, int> playerRanks;
    for(int i=0; i<players.size(); i++) {
        playerRanks[players[i]] = i;
    }
    int rank;
    string temp1, temp2;
    for(int i=0; i<callings.size(); i++) {
        rank = playerRanks[callings[i]];
        temp1 = players[rank-1];
        temp2 = players[rank];
        players[rank-1] = temp2;
        players[rank] = temp1;
        playerRanks[temp1]++;
        playerRanks[temp2]--;
    }
    return players;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}