-
Notifications
You must be signed in to change notification settings - Fork 0
/
문자열 압축.cpp
56 lines (45 loc) · 966 Bytes
/
문자열 압축.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int sol(string& s, int len) {
int ret = 0;
int cnt = 1;
for (int i = len; i < s.size() ; i += len) {
string s1 = s.substr(i-len, len);
string s2 = s.substr(i, len);
//cout << s1 << "," << s2 << endl;
if (s1 == s2) {
cnt++;
}
else {
ret += len;
if (cnt != 1) ret += to_string(cnt).size();
cnt = 1;
}
if (i + len >= s.size()) {
ret += s2.size();
if (cnt != 1) ret += to_string(cnt).size();
}
//cout << ret << endl;
}
return ret;
}
int solution(string s) {
if (s.size() == 1) return 1;
int answer = 10000;
for (int i = 1; i <= s.size() / 2; i++) {
answer = min(answer,sol(s, i));
}
return answer;
}
int main() {
string cc = "a";
string a = "abcdefgkc";
string b = "ababcdcdababcdcd";
string s = "abcabcabcabcdededededede";
string c = "abcabcdede";
string x = "xababcdcdababcdcd";
cout << solution(cc);
}