Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c8bd67c

Browse files
committed
Lv1_문자열압축
1 parent f9a85ce commit c8bd67c

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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; // 1⁄2ÃÀÛ ÀÎμ¦1⁄2o
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+
}

‎Programmers/Lv1_문자열압축.cpp‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎Programmers/Programmers.vcxproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<ClCompile Include="Lv1\Lv1_문자열다루기기본.cpp">
5959
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
6060
</ClCompile>
61+
<ClCompile Include="Lv1\Lv1_문자열압축.cpp" />
6162
<ClCompile Include="Lv1\Lv1_문자열을정수로바꾸기.cpp">
6263
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
6364
</ClCompile>
@@ -130,7 +131,6 @@
130131
<ClCompile Include="Lv1\Lv1_행렬의덧셈.cpp">
131132
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
132133
</ClCompile>
133-
<ClCompile Include="Lv1_문자열압축.cpp" />
134134
<ClCompile Include="Lv2\Lv2_124나라의숫자.cpp">
135135
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
136136
</ClCompile>

‎Programmers/Programmers.vcxproj.filters‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
<ClCompile Include="Lv5\Lv5_후보키.cpp">
469469
<Filter>소스 파일</Filter>
470470
</ClCompile>
471-
<ClCompile Include="Lv1_문자열압축.cpp">
471+
<ClCompile Include="Lv1\Lv1_문자열압축.cpp">
472472
<Filter>소스 파일</Filter>
473473
</ClCompile>
474474
</ItemGroup>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /