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 23d54c9

Browse files
committed
Lv2_2개이하로다른비트
1 parent c8d67cb commit 23d54c9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
using namespace std;
5+
6+
vector<long long> solution(vector<long long> numbers) {
7+
vector<long long> answer;
8+
for (auto a : numbers) {
9+
if (a % 2 == 0) { // 짝수
10+
answer.push_back(a + 1);
11+
}
12+
else { // 홀수
13+
long long last = (a+1) & -a; // 1101 -> 1110 & 0011 = 0010
14+
answer.push_back((a|last) & ~(last>>1)); // (1101 | 0010) & ~(0001) = 1111 & 1110 = 1110
15+
}
16+
}
17+
return answer;
18+
}
19+
20+
int main() {
21+
vector<long long> answer = solution({ 2,7 });
22+
for (auto a : answer)
23+
cout << a << " ";
24+
return 0;
25+
}

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@
182182
<ClCompile Include="Lv2\Lv2_124나라의숫자.cpp">
183183
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
184184
</ClCompile>
185+
<ClCompile Include="Lv2\Lv2_2개이하로다른비트.cpp">
186+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
187+
</ClCompile>
185188
<ClCompile Include="Lv2\Lv2_H-Index.cpp">
186189
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
187190
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@
573573
<ClCompile Include="Lv2\Lv2_피로도.cpp">
574574
<Filter>소스 파일\Lv2</Filter>
575575
</ClCompile>
576+
<ClCompile Include="Lv2\Lv2_2개이하로다른비트.cpp">
577+
<Filter>소스 파일\Lv2</Filter>
578+
</ClCompile>
576579
</ItemGroup>
577580
<ItemGroup>
578581
<None Include="packages.config" />

0 commit comments

Comments
(0)

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