카카오 오픈채팅방
2019. 9. 18. 20:53ㆍ알고리즘/프로그래머스
문자열 처리와 map을 활용해 해결할 수 있는 문제
문제: https://www.welcomekakao.com/learn/courses/30/lessons/42888?language=cpp
깃허브주소: https://github.com/surinoel/boj/blob/master/Programmers_오픈채팅방.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <map> | |
#include <string> | |
#include <vector> | |
#include <sstream> | |
#include <iostream> | |
using namespace std; | |
map<string, string> m; | |
vector<string> solution(vector<string> record) { | |
vector<string> ret; | |
for (int i = 0; i < record.size(); i++) { | |
istringstream f(record[i]); | |
string s; | |
vector<string> tokens; | |
while (getline(f, s, ' ')) { | |
tokens.push_back(s); | |
} | |
if (tokens[0] == "Enter") { | |
m[tokens[1]] = tokens[2]; | |
string tans = tokens[1] + ",님이 들어왔습니다."; | |
ret.push_back(tans); | |
} | |
else if (tokens[0] == "Leave") { | |
string tans = tokens[1] + ",님이 나갔습니다."; | |
ret.push_back(tans); | |
} | |
else { | |
m[tokens[1]] = tokens[2]; | |
} | |
} | |
vector<string> ans; | |
for (int i = 0; i < ret.size(); i++) { | |
istringstream f(ret[i]); | |
vector<string> tokens; | |
string s; | |
while (getline(f, s, ',')) { | |
tokens.push_back(s); | |
} | |
ans.push_back(m[tokens[0]] + tokens[1]); | |
} | |
return ans; | |
} |
'알고리즘 > 프로그래머스' 카테고리의 다른 글
프로그래머스 더 맵게 (0) | 2019.09.21 |
---|---|
프로그래머스 예산 (0) | 2019.09.21 |
카카오 후보키 (0) | 2019.09.20 |
카카오 실패율 (0) | 2019.09.19 |
프로그래머스 K번째 수 (0) | 2019.09.18 |