-
-
Save niklasjang/7b7c02207d96f621a3f5d3192fa86942 to your computer and use it in GitHub Desktop.
[PS][KAKAO BLIND RECRUITMENT][2020][문자열 압축]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <string> | |
using namespace std; | |
int solution(string s) { | |
int size = s.size(); | |
int ans = size; | |
for (int i = 1; i <= size; i++) { | |
int curr = 0; | |
int strLen = s.length(); | |
string tans = ""; | |
int a = 1; | |
while (curr < strLen) { | |
string first = s.substr(curr, i); | |
curr += i; | |
string second = s.substr(curr, i); | |
if (first != second) { | |
if (a != 1) { | |
tans += to_string(a) + first; | |
} | |
else { | |
tans += first; | |
} | |
a = 1; | |
} | |
else { | |
a++; | |
} | |
if (curr + i >= strLen) { | |
if (a != 1) { | |
tans += to_string(a) + second; | |
} | |
else { | |
tans += second; | |
} | |
break; | |
} | |
//cout << first << "," << second << "\n"; | |
} | |
//cout << i << ":" << tans << "\n"; | |
ans = min(ans, (int)tans.length()); | |
} | |
return ans; | |
} | |
int main() { | |
string s; | |
cin >> s; | |
solution(s); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment