Notice
Recent Posts
Recent Comments
Today
Total
01-10 22:06
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[2019 KAKAO BLIND RECRUITMENT] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[2019 KAKAO BLIND RECRUITMENT] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ

WonderJay 2022. 7. 7. 11:19
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/42888

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

[C++]

#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <iostream>

using namespace std;

vector<string> solution(vector<string> record) {
    vector<string> answer;
    
    map<string, string> user_list;
    vector<string> log;
    vector<string> tok(3, "");
    vector<string> id_list;
    
    string enter_mes = "๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.";
    string leave_mes = "๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.";
    
    for(int i = 0 ; i < record.size(); i ++)
    {
        istringstream ss(record[i]);
        string buf = "";
        
        int k = 0;
        while(ss >> buf) tok[k++] = buf;

        
        if(tok[0] == "Enter")
        {
            user_list[tok[1]] = tok[2];
            id_list.push_back(tok[1]);
            log.push_back(enter_mes);
        }
        if(tok[0] == "Leave")
        {
            user_list.insert(make_pair(tok[1], user_list[tok[1]])); // insert id,name
            id_list.push_back(tok[1]);
            log.push_back(leave_mes);
        }
        if(tok[0] == "Change")
        {
            user_list[tok[1]] = tok[2];
        }  
    }
    

    for(int i = 0 ; i < log.size(); i++)
        answer.push_back(user_list[id_list[i]] + log[i]);

    
    return answer;
}

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments