Advertisement
anechka_ne_plach

Untitled

Oct 9th, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. struct dot {
  7.     int x, y;
  8. };
  9.  
  10. istream& operator>>(istream& is, dot& a) {
  11.     is >> a.x >> a.y;
  12.     return is;
  13. }
  14.  
  15. struct line {
  16.     int a, b, c;
  17.  
  18.     line(const dot& A, const dot& B) {
  19.         a = B.y - A.y;
  20.         b = A.x - B.x;
  21.         c = A.y * (B.x - A.x) - A.x * (B.y - A.y);
  22.     }
  23. };
  24.  
  25. bool on_line(dot& a, line& l) {
  26.     return a.x * l.a + a.y * l.b + l.c == 0;
  27. }
  28.  
  29. int sign(int s) {
  30.     if (s < 0) {
  31.          return -1;
  32.     } else if (s > 0) {
  33.         return 1;
  34.     } else {
  35.         return 0;
  36.     }
  37. }
  38.  
  39. int main() {
  40.     dot a, b, c, d;
  41.     cin >> a >> b >> c >> d;
  42.     line l1(a, b);
  43.     line l2(c, d);
  44.     if (l1.a * l2.b != l1.b * l2.a) {
  45.         cout << 1 << " ";
  46.         double x = - ((l1.c * l2.b - l2.c * l1.b) * 1.0 / (l1.a * l2.b - l2.a * l1.b));
  47.         double y = - ((l1.a * l2.c - l2.a * l1.c) * 1.0 /(l1.a * l2.b - l2.a * l1.b));
  48.         cout << fixed << setprecision(2) << x << " " << y << "\n";
  49.         return 0;
  50.     } else if (l1.c == l2.c) {
  51.         cout << 2 << "\n";
  52.         return 0;
  53.     } else {
  54.         cout << 0 << "\n";
  55.         return 0;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement