#include <string>
#include <vector>
#include <map>
#include <sstream>
using namespace std;
vector<string> solution(vector<string> record) {
vector<string> answer;
vector<pair<string,string>> v;
map<string, string> m;
for(int i=0;i<record.size();i++)
{
stringstream ss(record[i]);
string behave, uid, name;
ss >> behave;
if(behave == "Leave"){
ss >> uid;
}else{
ss >> uid;
ss >> name;
m[uid] = name;
}
if(behave != "Change") v.push_back({behave, uid});
}
for(int i=0;i<v.size();i++)
{
string str = m[v[i].second] + "님이";
if(v[i].first == "Enter"){
str += " 들어왔습니다.";
}else if(v[i].first == "Leave"){
str += " 나갔습니다.";
}
answer.push_back(str);
}
return answer;
}
- stringstream을 유용하게 쓸 수 있는 케이스!