Advertisement
AmidamaruZXC

Untitled

Jan 24th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     double xArr[3];
  9.     double x1, x2, x3, v1, v2, v3, time12, time23, time13;
  10.     cout << "Input x1: ";
  11.     cin >> x1;
  12.     cout << "Input speed of x1: ";
  13.     cin >> v1;
  14.     cout << "Input x2: ";
  15.     cin >> x2;
  16.     cout << "Input speed of x2: ";
  17.     cin >> v2;
  18.     cout << "Input x3: ";
  19.     cin >> x3;
  20.     cout << "Input speed of x3: ";
  21.     cin >> v3;
  22.     xArr[0] = min(min(x1, x2), x3);
  23.     xArr[1] = x1 + x2 + x3 - min(min(x1, x2), x3) - max(max(x1, x2), x3);
  24.     xArr[2] = max(max(x1, x2), x3);
  25.     time12 = (xArr[1] - xArr[0]) / (v1 - v2);
  26.     time13 = (xArr[2] - xArr[0]) / (v1 - v3);
  27.     time23 = (xArr[2] - xArr[1]) / (v2 - v3);
  28.     if (time12 >= 0)
  29.         cout << "Points x1 and x2 intersect at time: " << time12 << endl;
  30.     else
  31.         cout << "Points x1 and x2 do not intersect!\n";
  32.     if (time13 >= 0)
  33.         cout << "Points x1 and x3 intersect at time: " << time13 << endl;
  34.     else
  35.         cout << "Points x1 and x3 do not intersect!\n";
  36.     if (time23 >= 0)
  37.         cout << "Points x2 and x3 intersect at time: " << time23 << endl;
  38.     else
  39.         cout << "Points x2 and x3 do not intersect!\n";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement