diff --git "a/mj010504/Programmers/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" "b/mj010504/Programmers/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" new file mode 100644 index 0000000..408ac58 --- /dev/null +++ "b/mj010504/Programmers/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251.cpp" @@ -0,0 +1,61 @@ +#include + +using namespace std; + +struct chat { + char c; + string id, name; +}; + +map mp; // id, name + +chat toChat(string input) { + vector sv; string temp; + stringstream ss(input); + + while(getline(ss, temp, ' ')) { + sv.push_back(temp); + } + + if(sv.size() == 2) { + return {'l', sv[1], mp[sv[1]]}; + } + + if(sv.size() == 3) { + mp[sv[1]] = sv[2]; + + if(sv[0] == "Enter") return {'e', sv[1], sv[2]}; + else{ // change + return {'c', sv[1], sv[2]}; + } + } +} + +string toKoreanChat(chat ct) { + string temp = ""; + string name = mp[ct.id]; + if(ct.c == 'l') { + temp = name + "님이 나갔습니다."; + } + + if(ct.c == 'e') { + temp = name + "님이 들어왔습니다."; + } + + return temp; +} + +vector solution(vector rv) { + vector res; + vector chats; + for(int i = 0; i < rv.size(); i++) { + auto ct = toChat(rv[i]); + if(ct.c != 'c') chats.push_back(toChat(rv[i])); + } + + for(auto ct : chats) { + res.push_back(toKoreanChat(ct)); + } + + return res; +}