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+ }
0 commit comments