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 93f81e4

Browse files
committed
Lv2_이진변환반복하기
1 parent d774884 commit 93f81e4

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
string digit(int n) {
8+
string s = "";
9+
while (n != 0) {
10+
s = s+ to_string(n % 2);
11+
n /= 2;
12+
}
13+
return s;
14+
}
15+
16+
int countZero(string s) {
17+
int ret = 0;
18+
for (auto a : s) {
19+
if (a == '0')
20+
++ret;
21+
}
22+
return ret;
23+
}
24+
25+
vector<int> solution(string s) {
26+
vector<int> answer;
27+
28+
int cnt=0,zcnt = 0;
29+
int round = 0;
30+
31+
do {
32+
zcnt = countZero(s);
33+
cnt += zcnt;
34+
s.erase(remove(s.begin(), s.end(), '0'), s.end());
35+
s = digit(s.length());
36+
++round;
37+
} while (s != "1");
38+
39+
answer.push_back(round);
40+
answer.push_back(cnt);
41+
42+
return answer;
43+
}
44+
45+
int main() {
46+
vector<int> ans = solution("01110");
47+
for (auto a : ans)
48+
cout << a << " ";
49+
return 0;
50+
}

‎Programmers/Programmers.vcxproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@
287287
<ClCompile Include="Lv2\Lv2_위장.cpp">
288288
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
289289
</ClCompile>
290+
<ClCompile Include="Lv2\Lv2_이진변환반복하기.cpp">
291+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
292+
</ClCompile>
290293
<ClCompile Include="Lv2\Lv2_전력망을둘로나누기.cpp">
291294
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
292295
</ClCompile>

‎Programmers/Programmers.vcxproj.filters‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@
588588
<ClCompile Include="Lv2\Lv2_모음사전.cpp">
589589
<Filter>소스 파일\Lv2</Filter>
590590
</ClCompile>
591+
<ClCompile Include="Lv2\Lv2_이진변환반복하기.cpp">
592+
<Filter>소스 파일\Lv2</Filter>
593+
</ClCompile>
591594
</ItemGroup>
592595
<ItemGroup>
593596
<None Include="packages.config" />

0 commit comments

Comments
(0)

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