-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkakao-4.cpp
More file actions
64 lines (62 loc) · 1.32 KB
/
kakao-4.cpp
File metadata and controls
64 lines (62 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 오픈채팅방
// 2019.08.29
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<map>
using namespace std;
vector<string> solution(vector<string> record) {
vector<string> answer;
map<string, string> info; // 유저아이디,유저닉네임을 가지고있는 맵
vector<string> log;
string buf;
// 들어오고 아이디 바꾼것을 먼저 체크함
for (int i = 0; i < record.size(); i++)
{
log.clear();
// log[0] : Enter,Leave,Change
// log[1] : 유저 아이디
// log[2] : 닉네임
stringstream ss(record[i]);
while (ss >> buf)
{
log.push_back(buf);
}
// 방에 들어오면 맵에 추가
if (log[0] == "Enter")
{
info[log[1]] = log[2];
}
// 닉네임을 변경함
else if (log[0] == "Change")
{
info.find(log[1])->second = log[2];
}
}
// 다시 돌면서 로그 answer에 저장
for (int i = 0; i < record.size(); i++)
{
log.clear();
stringstream ss(record[i]);
while (ss >> buf)
{
log.push_back(buf);
}
// 방에 들어옴
if (log[0] == "Enter")
{
buf = info.find(log[1])->second;
buf += "님이 들어왔습니다.";
answer.push_back(buf);
}
// 방에서 나감
else if (log[0] == "Leave")
{
buf = info.find(log[1])->second;
buf += "님이 나갔습니다.";
answer.push_back(buf);
}
}
return answer;
}