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 92ee077

Browse files
committed
Lv2_n^2배열자르기
1 parent 93f81e4 commit 92ee077

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
using namespace std;
5+
6+
vector<int> solution(int n, long long left, long long right) {
7+
vector<int> answer;
8+
9+
int ln = left / n;
10+
int lm = left % n;
11+
int rn = right / n;
12+
int rm = right % n;
13+
14+
// 왼쪽
15+
if (ln != rn) {
16+
for (int i = lm + 1; i <= n; ++i) {
17+
if (i < ln + 1)
18+
answer.push_back(ln + 1);
19+
else
20+
answer.push_back(i);
21+
}
22+
23+
// 중간
24+
for (int i = ln + 1; i < rn; ++i) {
25+
for (int k = 0; k < i + 1; ++k)
26+
answer.push_back(i + 1);
27+
for (int j = i + 2; j <= n; ++j)
28+
answer.push_back(j);
29+
}
30+
31+
// 오른쪽
32+
for (int i = 0; i <= rm; ++i) {
33+
if (i < rn + 1)
34+
answer.push_back(rn + 1);
35+
else
36+
answer.push_back(i + 1);
37+
}
38+
}
39+
else {
40+
for (int i = lm; i <= rm; ++i) {
41+
if (i < rn + 1)
42+
answer.push_back(rn + 1);
43+
else
44+
answer.push_back(i + 1);
45+
}
46+
}
47+
48+
return answer;
49+
}
50+
51+
int main() {
52+
vector<int> ans = solution(4,4,7);
53+
for (auto a : ans)
54+
cout << a << " ";
55+
return 0;
56+
}

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@
191191
<ClCompile Include="Lv2\Lv2_JadenCase문자열만들기.cpp">
192192
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
193193
</ClCompile>
194+
<ClCompile Include="Lv2\Lv2_n^2배열자르기.cpp">
195+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
196+
</ClCompile>
194197
<ClCompile Include="Lv2\Lv2_N개의최소공배수.cpp">
195198
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
196199
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,9 @@
591591
<ClCompile Include="Lv2\Lv2_이진변환반복하기.cpp">
592592
<Filter>소스 파일\Lv2</Filter>
593593
</ClCompile>
594+
<ClCompile Include="Lv2\Lv2_n^2배열자르기.cpp">
595+
<Filter>소스 파일\Lv2</Filter>
596+
</ClCompile>
594597
</ItemGroup>
595598
<ItemGroup>
596599
<None Include="packages.config" />

0 commit comments

Comments
(0)

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