Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions ChanhuiSeok/[2]KAKAO/2018KAKAO-압축.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <unordered_map>
#include <set>
#include <algorithm>

using namespace std;

unordered_map<string, int> maps;
string arr[27];

vector<int> solution(string msg) {
vector<int> answer;

string target;
string copymsg = msg;
string tmp = msg;
int idx = 1;
int endIdx = 27;
int index = 0;

while (!tmp.empty()) {
// �������� ���� �Է°� ��ġ�ϴ� ���� �� ���ڿ� w ã��
while (idx <= tmp.length()) {
// ���� ���ڿ��� 1, 2, 3,... ���� ��� ã�ƺ���
target = tmp.substr(0, idx);
if (maps.count(target)) {
index = maps[target];
idx++;
continue;
}
// �������� � �� ���� ���
else {
// ���� �� ���ڿ��� ���� ��ȣ ����
break;
}
}

// ���� �� ���ڿ��� ���� ��ȣ�� index�� ����Ǿ� ����
answer.push_back(index);

// �Է¿��� w ����
tmp = tmp.substr(idx - 1);

// �Է¿��� ó������ ���� ���ڰ� ���� ������ ������ ����
maps.insert({ target, endIdx++ });

// idx �ʱ�ȭ
idx = 1;
}

return answer;
}

int main() {

ios::sync_with_stdio(0);
cin.tie(0);

// maps �ʱ�ȭ
for (int i = 1; i <= 26; i++) {
arr[i] = 'A' + i - 1;
maps[arr[i]] = i;
}

vector<int> answer = solution("ABABABABABABABAB");

return 0;
}