-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLv5_압축.cpp
More file actions
39 lines (37 loc) · 704 Bytes
/
Lv5_압축.cpp
File metadata and controls
39 lines (37 loc) · 704 Bytes
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
#include <string>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
vector<int> solution(string msg) {
vector<int> answer;
map<string, int> dic;
int num;
for (num = 1; num <= 26; ++num) {
char c = 'A' + num -1;
string temp;
temp = c;
dic.insert({ temp ,num });
}
bool flag = true;
for (int i = 0; i < msg.length(); ++i) {
flag = true;
string temp = "";
string prev = "";
while (flag) {
temp += msg[i];
if (dic.count(temp) > 0) { // 사전에 있음
i++;
prev = temp;
}
else { // 사전에 없음
flag = false;
answer.push_back(dic[prev]);
dic.insert({ temp, num });
++num;
--i;
}
}
}
return answer;
}