File tree Expand file tree Collapse file tree 4 files changed +56
-14
lines changed Expand file tree Collapse file tree 4 files changed +56
-14
lines changed Original file line number Diff line number Diff line change
1
+ #include < string>
2
+ #include < vector>
3
+ #include < algorithm>
4
+ #include < iostream>
5
+ using namespace std ;
6
+
7
+ int solution (string s) {
8
+ int slen = s.length ();
9
+ int answer = slen;
10
+
11
+ for (int i = 1 ; i <= slen; ++i) {
12
+ int ans = i;
13
+ string start = s.substr (0 , i);
14
+ int index = i; // ½ÃÀÛ À妽º
15
+ int count = 1 ;
16
+
17
+ while (index < slen) {
18
+ int npos = i;
19
+ if (index + npos >= slen)
20
+ npos = slen - index;
21
+
22
+ string ns = s.substr (index, npos);
23
+
24
+ if (start == ns) {
25
+ ++count;
26
+ }
27
+ else {
28
+ if (count != 1 ) {
29
+ int num = to_string (count).length ();
30
+ ans += num;
31
+ }
32
+ ans += npos;
33
+ count = 1 ;
34
+ }
35
+
36
+ start = ns;
37
+ index += npos;
38
+ }
39
+ if (count != 1 ) {
40
+ int num = to_string (count).length ();
41
+ ans += num;
42
+ }
43
+ answer = min (answer, ans);
44
+ }
45
+
46
+ return answer;
47
+ }
48
+
49
+ int main () {
50
+
51
+ cout << solution (" aabbaccc" );
52
+
53
+ return 0 ;
54
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 58
58
<ClCompile Include =" Lv1\Lv1_문자열다루기기본.cpp" >
59
59
<ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >true</ExcludedFromBuild >
60
60
</ClCompile >
61
+ <ClCompile Include =" Lv1\Lv1_문자열압축.cpp" />
61
62
<ClCompile Include =" Lv1\Lv1_문자열을정수로바꾸기.cpp" >
62
63
<ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >true</ExcludedFromBuild >
63
64
</ClCompile >
130
131
<ClCompile Include =" Lv1\Lv1_행렬의덧셈.cpp" >
131
132
<ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >true</ExcludedFromBuild >
132
133
</ClCompile >
133
- <ClCompile Include =" Lv1_문자열압축.cpp" />
134
134
<ClCompile Include =" Lv2\Lv2_124나라의숫자.cpp" >
135
135
<ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >true</ExcludedFromBuild >
136
136
</ClCompile >
Original file line number Diff line number Diff line change 468
468
<ClCompile Include =" Lv5\Lv5_후보키.cpp" >
469
469
<Filter >소스 파일</Filter >
470
470
</ClCompile >
471
- <ClCompile Include =" Lv1_문자열압축.cpp" >
471
+ <ClCompile Include =" Lv1\ Lv1_문자열압축.cpp" >
472
472
<Filter >소스 파일</Filter >
473
473
</ClCompile >
474
474
</ItemGroup >
You can’t perform that action at this time.
0 commit comments