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 4f1ab6c

Browse files
committed
Lv1_키패드누르기
Lv2_행렬테두리회전하기
1 parent 7d54099 commit 4f1ab6c

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

‎Programmers/Lv1/Lv1_키패드누르기.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ string solution(vector<int> numbers, string hand) {
3232
int left_diff = 0;
3333
int right_diff = 0;
3434

35-
// 왼손과의 거리
35+
// ?1⁄4손ê31⁄4ì ̃ 거리
3636
if (left == 2 || left == 5 || left == 8 || left == 11)
3737
left_diff = abs(number - left) / 3;
3838
else
3939
left_diff = dist[left][number];
4040

4141

42-
// 오른손과의 거리
42+
// ?¤ë\ ̧?ê31⁄4??거리
4343
if (right == 2 || right == 5 || right == 8 || right == 11)
4444
right_diff = abs(number - right) / 3;
4545
else
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
using namespace std;
5+
6+
int arr[101][101];
7+
8+
int rotate(int y1, int x1, int y2, int x2) {
9+
int ret = 987654321;
10+
int y1x1 = arr[y1][x1];
11+
int y1x2 = arr[y1][x2];
12+
int y2x1 = arr[y2][x1];
13+
int y2x2 = arr[y2][x2];
14+
15+
int origin = arr[y1][x1];
16+
if (ret > origin)
17+
ret = origin;
18+
19+
// 위쪽
20+
int temp = 0;
21+
for (int i = x1 + 1; i <= x2; ++i) {
22+
temp = origin;
23+
origin = arr[y1][i];
24+
arr[y1][i] = temp;
25+
if (ret > origin)
26+
ret = origin;
27+
}
28+
29+
// 오른쪽
30+
for (int i = y1+1; i <= y2; ++i) {
31+
temp = origin;
32+
origin = arr[i][x2];
33+
arr[i][x2] = temp;
34+
if (ret > origin)
35+
ret = origin;
36+
}
37+
38+
// 아래쪽
39+
for (int i = x2 - 1; i >= x1; --i) {
40+
temp = origin;
41+
origin = arr[y2][i];
42+
arr[y2][i] = temp;
43+
if (ret > origin)
44+
ret = origin;
45+
}
46+
47+
// 왼쪽
48+
for (int i = y2 - 1; i >= y1; --i) {
49+
temp = origin;
50+
origin = arr[i][x1];
51+
arr[i][x1] = temp;
52+
if (ret > origin)
53+
ret = origin;
54+
}
55+
56+
return ret;
57+
}
58+
59+
vector<int> solution(int rows, int columns, vector<vector<int>> queries) {
60+
vector<int> answer;
61+
62+
int count = 1;
63+
for (int i = 1; i <= rows; ++i) {
64+
for (int j = 1; j <= columns; ++j)
65+
arr[i][j] = count++;
66+
}
67+
68+
for (auto a : queries)
69+
answer.push_back(rotate(a[0], a[1], a[2], a[3]));
70+
71+
return answer;
72+
}
73+
74+
int main() {
75+
int rows = 6;
76+
int columns = 6;
77+
vector<vector<int>> queries = {{2, 2, 5, 4}, { 3, 3, 6, 6 }, { 5, 1, 6, 3 }};
78+
79+
vector<int> ans = solution(rows, columns, queries);
80+
81+
for (auto a : ans)
82+
cout << a << " ";
83+
84+
return 0;
85+
}
86+

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@
292292
<ClCompile Include="Lv2\Lv2_행렬의곱셈.cpp">
293293
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
294294
</ClCompile>
295+
<ClCompile Include="Lv2\Lv2_행렬테두리회전하기.cpp">
296+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
297+
</ClCompile>
295298
<ClCompile Include="Lv3\Lv3_2xn타일링.cpp">
296299
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
297300
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,5 +519,8 @@
519519
<ClCompile Include="Lv1\Lv1_부족한금액계산하기.cpp">
520520
<Filter>소스 파일</Filter>
521521
</ClCompile>
522+
<ClCompile Include="Lv2\Lv2_행렬테두리회전하기.cpp">
523+
<Filter>소스 파일</Filter>
524+
</ClCompile>
522525
</ItemGroup>
523526
</Project>

0 commit comments

Comments
(0)

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