728x90
#include <string>
#include <vector>
#include <tuple>
#include <map>
using namespace std;
vector<string> solution(vector<string> record) {
vector<string> answer;
map<string, int> m;
vector<string> ids;
vector<string> nicknames;
vector<pair<int, string>> ment;
for (int i = 0; i < record.size(); i++) {
if (record[i][0] == 'E') {
int j = 6;
while (record[i][j] != ' ') {
j++;
}
string id = record[i].substr(6, j - 6);
string nickname = record[i].substr(j + 1);
//answer.push_back(nickname + "님이 들어왔습니다.");
if (m.find(id) != m.end()) {
nicknames[m[id]] = nickname;
}
else {
ids.push_back(id);
nicknames.push_back(nickname);
m[id] = ids.size() - 1;
}
ment.push_back(make_pair(m[id], "님이 들어왔습니다."));
}
else if (record[i][0] == 'L') {
string id = record[i].substr(6);
ment.push_back(make_pair(m[id], "님이 나갔습니다."));
}
else if (record[i][0] == 'C') {
int j = 7;
while (record[i][j] != ' ') {
j++;
}
string id = record[i].substr(7, j - 7);
string nickname = record[i].substr(j + 1);
nicknames[m[id]] = nickname;
}
}
for (pair<int, string> t : ment) {
string temp = nicknames[t.first] + t.second;
answer.push_back(temp);
}
return answer;
}
728x90
'알고리즘 문제' 카테고리의 다른 글
[백준] 1120번 문자열 (0) | 2020.02.09 |
---|---|
[백준] 1547번 공 (0) | 2020.02.09 |
[백준] 3613번 Java vs C++ (0) | 2020.02.08 |
[백준] 10808번 알파벳 개수 (0) | 2020.02.08 |
[백준] 11403번 경로 찾기 (0) | 2020.02.07 |