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 2f40b07

Browse files
committed
Lv2_삼각달팽이
1 parent 23d54c9 commit 2f40b07

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

‎Programmers/Lv2/Lv2_삼각달팽이.cpp

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 <iostream>
4+
using namespace std;
5+
6+
vector<int> solution(int n) {
7+
int size = (n * (n + 1)) / 2;
8+
vector<int> answer(size,0);
9+
10+
int idx = 0;
11+
int cnt = 1;
12+
int dir = 1;
13+
int origin = n;
14+
int cycle = 0;
15+
16+
answer[0] = 1;
17+
for (int i = 2; i <= size; ++i) {
18+
if (cnt < n) {
19+
if (dir % 3 == 1) {
20+
idx += cnt+cycle;
21+
}
22+
else if (dir % 3 == 2) {
23+
++idx;
24+
}
25+
else {
26+
idx -= (origin-cnt);
27+
}
28+
++cnt;
29+
}
30+
else {
31+
if (dir % 3 != 2)
32+
++cycle;
33+
++dir;
34+
if (dir % 3 == 1)
35+
--origin;
36+
--n;
37+
cnt = 0;
38+
--i;
39+
continue;
40+
}
41+
answer[idx] = i;
42+
}
43+
44+
return answer;
45+
}
46+
47+
int main() {
48+
vector<int> answer = solution(6);
49+
50+
for (auto a : answer)
51+
cout << a << " ";
52+
53+
return 0;
54+
}

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@
242242
<ClCompile Include="Lv2\Lv2_빛의경로사이클.cpp">
243243
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
244244
</ClCompile>
245+
<ClCompile Include="Lv2\Lv2_삼각달팽이.cpp">
246+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
247+
</ClCompile>
245248
<ClCompile Include="Lv2\Lv2_소수만들기.cpp">
246249
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
247250
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@
576576
<ClCompile Include="Lv2\Lv2_2개이하로다른비트.cpp">
577577
<Filter>소스 파일\Lv2</Filter>
578578
</ClCompile>
579+
<ClCompile Include="Lv2\Lv2_삼각달팽이.cpp">
580+
<Filter>소스 파일\Lv2</Filter>
581+
</ClCompile>
579582
</ItemGroup>
580583
<ItemGroup>
581584
<None Include="packages.config" />

0 commit comments

Comments
(0)

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