카카오 코딩 테스트 풀이
오픈채팅방 풀이
by paysmile
2019. 9. 1.
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
vector<string> solution(vector<string> record) {
vector<string> answer;
queue<pair<string , string>> q;
map<string, string> id;
for (int i = 0; i < record.size(); i++) {
string str;
vector<string> temp;
for (int j = 0; j < record[i].size(); j++) {
if (record[i][j] == ' ') {
temp.push_back(str);
str.clear();
}
else
str.push_back(record[i][j]);
}
temp.push_back(str);
if(temp[0][0] == 'C'){
id[temp[1]] = temp[2];
}
else {
if (temp[0][0] == 'E')
id[temp[1]] = temp[2];
q.push(make_pair(temp[0], temp[1]));
}
}
while(!q.empty()){
string cmd = q.front().first;
string idname = q.front().second;
q.pop();
if(cmd == "Enter")
answer.push_back(id[idname]+"님이 들어왔습니다.");
else
answer.push_back(id[idname] + "님이 나갔습니다.");
}
return answer;
}