SHARE
TWEET

Untitled

a guest Sep 17th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <queue>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. vector<string> solution(vector<string> record) {
  10.     vector<string> answer;
  11.     queue<pair<string, string>> q;
  12.     map<string, string> m;
  13.  
  14.     for (int i = 0; i < record.size(); i++)
  15.     {
  16.         string tmp;
  17.         vector<string> v;
  18.         for (int j = 0; j < record[i].size(); j++) {
  19.             if (record[i][j] == ' ') {
  20.                 v.push_back(tmp);
  21.                 tmp.clear();
  22.             }
  23.             else tmp.push_back(record[i][j]);
  24.         }
  25.         v.push_back(tmp);
  26.  
  27.         if (v[0] == "Change") {
  28.             m[v[1]] = v[2];
  29.         }
  30.         else if (v[0] == "Leave") {
  31.             q.push(make_pair(v[0], v[1]));
  32.         }
  33.         else if (v[0] == "Enter") {
  34.             q.push(make_pair(v[0], v[1]));
  35.             m[v[1]] = v[2];
  36.         }
  37.     }
  38.     while (!q.empty()) {
  39.         string x = q.front().first;
  40.         string y = q.front().second;
  41.         string result;
  42.         q.pop();
  43.         if (x == "Enter")
  44.             result = m[y] + "님이 들어왔습니다.";
  45.         else
  46.             result = m[y] + "님이 나갔습니다.";
  47.  
  48.         answer.push_back(result);
  49.     }
  50.  
  51.     return answer;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top