Hello Ocean! ๐ŸŒผ

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/์นด์นด์˜ค ์ฝ”ํ…Œ] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ ๋ณธ๋ฌธ

Algorithm

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/์นด์นด์˜ค ์ฝ”ํ…Œ] ์˜คํ”ˆ์ฑ„ํŒ…๋ฐฉ

bba_dda 2020. 11. 22. 13:17
๋ฐ˜์‘ํ˜•

ver 1

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

using namespace std;

vector<string> solution(vector<string> record) {
    vector<string> answer;
    map<string, string> dict;
    for (int i = 0;i < record.size();i++) {
        vector<string> splited;
        istringstream temp(record[i]);
        string stringBuffer;
        while (getline(temp, stringBuffer, ' '))
        {
            splited.push_back(stringBuffer);
        }
        if (splited[0] == "Enter" || splited[0] == "Change")
            dict[splited[1]] = splited[2];
    }
    for (int i = 0;i < record.size();i++) {
        vector<string> splited;
        istringstream temp(record[i]);
        string stringBuffer;
        while (getline(temp, stringBuffer, ' '))
        {
            splited.push_back(stringBuffer);
        }
        string ans;
        if (splited[0] == "Enter") {
            ans = dict[splited[1]] + "๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.";
            answer.push_back(ans);
        }
        else if (splited[0] == "Leave") {
            ans = dict[splited[1]] + "๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.";
            answer.push_back(ans);
        }
    }
    return answer;
}
ํ…Œ์ŠคํŠธ 1 ใ€‰ ํ†ต๊ณผ (0.05ms, 3.89MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰ ํ†ต๊ณผ (0.04ms, 3.95MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰ ํ†ต๊ณผ (0.11ms, 3.82MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰ ํ†ต๊ณผ (0.13ms, 3.93MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰ ํ†ต๊ณผ (1.53ms, 3.94MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰ ํ†ต๊ณผ (1.73ms, 3.96MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰ ํ†ต๊ณผ (1.39ms, 3.93MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰ ํ†ต๊ณผ (1.67ms, 3.93MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰ ํ†ต๊ณผ (2.02ms, 3.93MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰ ํ†ต๊ณผ (1.72ms, 3.95MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰ ํ†ต๊ณผ (1.05ms, 3.95MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰ ํ†ต๊ณผ (1.03ms, 3.89MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰ ํ†ต๊ณผ (1.67ms, 3.91MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰ ํ†ต๊ณผ (2.02ms, 4.01MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰ ํ†ต๊ณผ (0.05ms, 3.97MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰ ํ†ต๊ณผ (0.04ms, 3.93MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰ ํ†ต๊ณผ (0.20ms, 3.97MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰ ํ†ต๊ณผ (0.21ms, 3.93MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰ ํ†ต๊ณผ (1.72ms, 4.11MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰ ํ†ต๊ณผ (1.49ms, 3.91MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰ ํ†ต๊ณผ (1.51ms, 3.96MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰ ํ†ต๊ณผ (1.53ms, 3.98MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰ ํ†ต๊ณผ (1.78ms, 4.04MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰ ํ†ต๊ณผ (1.83ms, 4MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰ ํ†ต๊ณผ (190.21ms, 41.7MB)
ํ…Œ์ŠคํŠธ 26 ใ€‰ ํ†ต๊ณผ (216.32ms, 39.9MB)
ํ…Œ์ŠคํŠธ 27 ใ€‰ ํ†ต๊ณผ (231.34ms, 41.4MB)
ํ…Œ์ŠคํŠธ 28 ใ€‰ ํ†ต๊ณผ (250.06ms, 46.4MB)
ํ…Œ์ŠคํŠธ 29 ใ€‰ ํ†ต๊ณผ (252.67ms, 46.3MB)
ํ…Œ์ŠคํŠธ 30 ใ€‰ ํ†ต๊ณผ (184.68ms, 39.4MB)
ํ…Œ์ŠคํŠธ 31 ใ€‰ ํ†ต๊ณผ (208.18ms, 40.6MB)
ํ…Œ์ŠคํŠธ 32 ใ€‰ ํ†ต๊ณผ (167.06ms, 38.2MB)

ver 2

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

using namespace std;

vector<string> solution(vector<string> record) {
    vector<string> answer;
    vector<vector<string>> data;
    map<string, string> dict;
    for (int i = 0;i < record.size();i++) {
        vector<string> splited;
        istringstream temp(record[i]);
        string stringBuffer;
        while (getline(temp, stringBuffer, ' '))
        {
            splited.push_back(stringBuffer);
        }
        if (splited[0] == "Enter" || splited[0] == "Change") 
            dict[splited[1]] = splited[2];
        if (splited[0] == "Enter" || splited[0] == "Leave") {
            vector<string> row = { splited[0],splited[1] };
            data.push_back(row);
        }
    }
    for (int i = 0;i < data.size();i++) {
        vector<string> row = data[i];
        string ans;
        if (row[0] == "Enter") {
            ans = dict[row[1]]+"๋‹˜์ด ๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.";
            answer.push_back(ans);
        }
        else if (row[0] == "Leave") {
            ans = dict[row[1]] + "๋‹˜์ด ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.";
            answer.push_back(ans);
        }

    }
    return answer;
}
ํ…Œ์ŠคํŠธ 1 ใ€‰ ํ†ต๊ณผ (0.04ms, 3.96MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰ ํ†ต๊ณผ (0.05ms, 3.93MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰ ํ†ต๊ณผ (0.10ms, 3.93MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰ ํ†ต๊ณผ (0.10ms, 3.94MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰ ํ†ต๊ณผ (1.09ms, 3.97MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰ ํ†ต๊ณผ (1.24ms, 4.07MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰ ํ†ต๊ณผ (1.03ms, 3.93MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰ ํ†ต๊ณผ (1.23ms, 3.95MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰ ํ†ต๊ณผ (1.67ms, 4.19MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰ ํ†ต๊ณผ (1.33ms, 3.94MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰ ํ†ต๊ณผ (0.82ms, 3.94MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰ ํ†ต๊ณผ (0.82ms, 3.94MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰ ํ†ต๊ณผ (1.24ms, 3.94MB)
ํ…Œ์ŠคํŠธ 14 ใ€‰ ํ†ต๊ณผ (1.57ms, 4MB)
ํ…Œ์ŠคํŠธ 15 ใ€‰ ํ†ต๊ณผ (0.04ms, 3.93MB)
ํ…Œ์ŠคํŠธ 16 ใ€‰ ํ†ต๊ณผ (0.04ms, 3.93MB)
ํ…Œ์ŠคํŠธ 17 ใ€‰ ํ†ต๊ณผ (0.17ms, 3.94MB)
ํ…Œ์ŠคํŠธ 18 ใ€‰ ํ†ต๊ณผ (0.15ms, 3.94MB)
ํ…Œ์ŠคํŠธ 19 ใ€‰ ํ†ต๊ณผ (1.42ms, 3.97MB)
ํ…Œ์ŠคํŠธ 20 ใ€‰ ํ†ต๊ณผ (1.03ms, 3.93MB)
ํ…Œ์ŠคํŠธ 21 ใ€‰ ํ†ต๊ณผ (1.03ms, 3.95MB)
ํ…Œ์ŠคํŠธ 22 ใ€‰ ํ†ต๊ณผ (1.10ms, 3.93MB)
ํ…Œ์ŠคํŠธ 23 ใ€‰ ํ†ต๊ณผ (1.28ms, 4.01MB)
ํ…Œ์ŠคํŠธ 24 ใ€‰ ํ†ต๊ณผ (1.37ms, 4.09MB)
ํ…Œ์ŠคํŠธ 25 ใ€‰ ํ†ต๊ณผ (161.58ms, 47.2MB)
ํ…Œ์ŠคํŠธ 26 ใ€‰ ํ†ต๊ณผ (190.26ms, 49.9MB)
ํ…Œ์ŠคํŠธ 27 ใ€‰ ํ†ต๊ณผ (208.04ms, 52.3MB)
ํ…Œ์ŠคํŠธ 28 ใ€‰ ํ†ต๊ณผ (219.66ms, 53.8MB)
ํ…Œ์ŠคํŠธ 29 ใ€‰ ํ†ต๊ณผ (210.52ms, 53.8MB)
ํ…Œ์ŠคํŠธ 30 ใ€‰ ํ†ต๊ณผ (154.95ms, 42.4MB)
ํ…Œ์ŠคํŠธ 31 ใ€‰ ํ†ต๊ณผ (187.32ms, 50.7MB)
ํ…Œ์ŠคํŠธ 32 ใ€‰ ํ†ต๊ณผ (144.40ms, 45.3MB)
๋ฐ˜์‘ํ˜•