혼종 꼬지마루
[프로그래머스] (2018)KAKAO BLIND - 오픈채팅방 본문
상당히 구현만을 위한 문제였다....
이 문제랑 실패율 두 문제 밖에 못풀었는데 오픈 채팅방 문제는 stl을 안쓰고 풀다가 시간초과가 계속 떠서 오래걸림...
stl 쓰자마자 바로 통과!!
그냥 문제의 조건에 맞게 구현만 잘해주면 된다. map과 vector, string 만 잘 다뤄주면 된다
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 | #include <string> #include <vector> #include <map> #include <cstring> using namespace std; vector<string> solution(vector<string> record) { vector<string> answer; vector<string> tmp; vector<int> inout; map<string, string> list; int len = record.size(); for (int i = 0; i < len; i++) { char state[10] = { 0 }, id[12] = { 0 }, nick[12] = { 0 }; int st = 0, j = 0; while (1) { if (record[i][j] == ' ') break; state[st++] = record[i][j]; j++; } j++; st = 0; while (1) { if (!strcmp(state, "Leave")) if (j == record[i].size()) break; if (record[i][j] == ' ') break; id[st++] = record[i][j]; j++; } if (strcmp(state, "Leave")) { j++; st = 0; while (1) { if (j == record[i].size()) break; nick[st++] = record[i][j]; j++; } } if (!strcmp(state, "Enter")) { tmp.push_back(id); inout.push_back(1); list[id] = nick; } else if (!strcmp(state, "Leave")) { tmp.push_back(id); inout.push_back(2); } else { list[id] = nick; } } for (int i = 0; i < tmp.size(); i++) if (inout[i] == 1) answer.push_back(list[tmp[i]] + "님이 들어왔습니다."); else answer.push_back(list[tmp[i]] + "님이 나갔습니다."); return answer; } int main(void) { vector <string> a = { "Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan" }; vector<string> ret = solution(a); return 0; } | cs |
'Algorithms > SIMULATION' 카테고리의 다른 글
[백준] 17135 - 캐슬 디펜스 (0) | 2019.04.07 |
---|---|
[프로그래머스] (2018)KAKAO BLIND - 실패율 (0) | 2018.11.11 |
[백준] 16235 - 나무 재태크 (0) | 2018.11.08 |
[SWEA] 5650 - 핀볼 게임 (0) | 2018.09.21 |
[SWEA] 5658 - 보물상자 비밀번호 (0) | 2018.09.21 |