https://school.programmers.co.kr/learn/courses/30/lessons/42888
#include <string>
#include <vector>
#include <sstream>
#include <list>
#include <unordered_map>
using namespace std;
vector<string> solution(vector<string> record) {
vector<string> answer;
unordered_map<string, string> m;
list<pair<string, string>> li;
stringstream ss;
for (const auto& data : record) {
ss.str(data);
string command, userID, nickName; ss >> command >> userID >> nickName;
ss.clear();
if (command != "Change") li.emplace_back(make_pair(command, userID));
if (command != "Leave") m[userID] = nickName;
}
for (const auto& pair : li) {
const auto& command = pair.first, userID = pair.second;
if (command == "Enter") answer.emplace_back(m[userID] + "님이 들어왔습니다.");
else answer.emplace_back(m[userID] + "님이 나갔습니다.");
}
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (스택/큐) Lv 2. 주식가격 (0) | 2023.07.09 |
---|---|
[Programmers] Lv 2. 땅따먹기 (0) | 2023.07.09 |
[Programmers] (2022 KAKAO BLIND RECRUITMENT) Lv 2. 주차 요금 계산 (0) | 2023.07.07 |
[Programmers] (힙(Heap)) Lv 2. 더 맵게 (0) | 2023.07.04 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] n진수 게임 (0) | 2023.07.03 |
댓글