Skip to content

Commit ba25dce

Browse files
committed
Lv2_교점에별만들기
1 parent ece6c81 commit ba25dce

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <climits>
5+
#include <algorithm>
6+
using namespace std;
7+
8+
vector<string> solution(vector<vector<int>> line) {
9+
vector<string> answer;
10+
vector<pair<long long, long long>> cross;
11+
12+
long long minX = LLONG_MAX, minY = LLONG_MAX;
13+
long long maxX = LLONG_MIN, maxY = LLONG_MIN;
14+
15+
for (int i = 0; i < line.size() - 1; ++i) {
16+
long long a = line[i][0];
17+
long long b = line[i][1];
18+
long long e = line[i][2];
19+
for (int j = i + 1; j < line.size(); ++j) {
20+
long long c = line[j][0];
21+
long long d = line[j][1];
22+
long long f = line[j][2];
23+
24+
long long x1 = b * f - e * d;
25+
long long y1 = e * c - a * f;
26+
long long common = a * d - b * c;
27+
28+
if (common == 0)
29+
continue;
30+
31+
if (x1 % common == 0 && y1 % common==0) {
32+
long long ix = x1 / common;
33+
long long iy = y1 / common;
34+
35+
if (maxX < ix)
36+
maxX = ix;
37+
if (minX > ix)
38+
minX = ix;
39+
if (maxY < iy)
40+
maxY = iy;
41+
if (minY > iy)
42+
minY = iy;
43+
cross.push_back({ ix, iy });
44+
}
45+
}
46+
}
47+
48+
string s = "";
49+
for (long long j = 0; j <= maxX - minX; ++j)
50+
s += ".";
51+
52+
for (long long i = 0; i <= maxY - minY; ++i)
53+
answer.push_back(s);
54+
55+
for (auto a : cross)
56+
answer[a.second - minY][a.first - minX] = '*';
57+
58+
reverse(answer.begin(), answer.end());
59+
return answer;
60+
}
61+
62+
int main() {
63+
vector<vector<int>> line = {{2, -1, 4}, {-2, -1, 4}, {0, -1, 1}, {5, -8, -12}, {5, 8, 12}};
64+
vector<vector<int>> line1 = { {0, 1, -1},{1, 0, -1},{1, 0, 1 }};
65+
vector<string> answer = solution(line);
66+
for (auto a : answer)
67+
cout << a << endl;
68+
69+
return 0;
70+
}

Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@
209209
<ClCompile Include="Lv2\Lv2_괄호회전하기.cpp">
210210
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
211211
</ClCompile>
212+
<ClCompile Include="Lv2\Lv2_교점에별만들기.cpp">
213+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
214+
</ClCompile>
212215
<ClCompile Include="Lv2\Lv2_구명보트.cpp">
213216
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
214217
</ClCompile>

Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@
579579
<ClCompile Include="Lv2\Lv2_삼각달팽이.cpp">
580580
<Filter>소스 파일\Lv2</Filter>
581581
</ClCompile>
582+
<ClCompile Include="Lv2\Lv2_교점에별만들기.cpp">
583+
<Filter>소스 파일\Lv2</Filter>
584+
</ClCompile>
582585
</ItemGroup>
583586
<ItemGroup>
584587
<None Include="packages.config" />

0 commit comments

Comments
 (0)