fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. double x1, y1, x2, y2, x3, y3, x4, y4;
  7. double Ua, Ub;
  8. cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
  9. double D = (x1-x2)*(y4-y3)-(x4-x3)*(y1-y2);
  10. if (D == 0) cout << "...to be continue...";
  11. else {
  12. Ua=((x4-x2)*(y4-y3)-(x4-x3)*(y4-y2)) / D;
  13. Ub=((x1-x2)*(y4-y2)-(x4-x2)*(y1-y2)) / D;
  14. cout << Ua << " " << Ub << endl;
  15. cout << "The segments " << ( Ua<=1 && Ua>=0 && Ub<=1 && Ub>=0 ? "" : "do not") << "intersect";
  16. }
  17. return 0;
  18. }
Success #stdin #stdout 0s 16064KB
stdin
0 0 0 1
1 0 1 1
stdout
...to be continue...