알고리즘/알고리즘 문제
[카카오 코딩테스트] 오픈채팅방
charminseok
2019. 9. 10. 13:53
https://www.welcomekakao.com/learn/courses/30/lessons/42888
코딩테스트 연습 - 오픈채팅방 | 프로그래머스
오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오픈 채팅방을 개설한 사람을 위해, 다양한 사람들이 들어오고, 나가는 것을 지켜볼 수 있는 관리자창을 만들기로 했다. 채팅방에 누군가 들어오면 다음 메시지가 출력된다. [닉네임]님이 들어왔습니다. 채팅방에서 누군가 나가면 다음 메시지가 출력된다. [닉네임]님이 나갔습니다. 채팅
www.welcomekakao.com
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
|
#include <string>
#include <vector>
#include<map>
using namespace std;
vector<string> solution(vector<string> record) {
vector<string> answer;
vector<pair<string, string>> chat;
map<string, string> user;
int logIdx = 0;
for (int i = 0; i < record.size(); i++) {
string log = record[i];
int idx = 0;
string command[3];
for (int j = 0; j < log.size(); j++) {
char c = log[j];
if (c == ' ') idx++;
else command[idx] += c;
}
if (command[0] != "Change") {
chat.push_back({ command[0],command[1] });
}
if (command[0] != "Leave") {
user[command[1]] = command[2];
}
}
for (int i = 0; i < chat.size(); i++) {
string msg = "";
pair<string, string> tmp;
tmp = chat[i];
}
}
answer.push_back(msg);
}
return answer;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|