fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. using namespace std;
  5.  
  6. typedef pair<int,int> point;
  7.  
  8. int SegmentsAreParallel(const point & i, const point & j, const point & k)
  9. {
  10. int dx1, dy1, dx2, dy2;
  11.  
  12. dx1 = j.first - i.first;
  13. dy1 = j.second - i.second;
  14.  
  15. dx2 = k.first - i.first;
  16. dy2 = k.second - i.second;
  17.  
  18. return dx1 * dy2 - dy1 * dx2 == 0;
  19. }
  20.  
  21. int main()
  22. {
  23. point p1(0, 0);
  24. point p2(1, 1);
  25. point p3(2, 2);
  26. point p4(-1, -1);
  27. point p5(1, -1);
  28. point p6(0, 10);
  29. point p7(0, 100);
  30. point p8(10, 0);
  31. point p9(100, 0);
  32.  
  33. cout << SegmentsAreParallel(p1, p2, p3) << endl;
  34. cout << SegmentsAreParallel(p1, p2, p4) << endl;
  35. cout << SegmentsAreParallel(p1, p2, p5) << endl;
  36. cout << SegmentsAreParallel(p1, p6, p7) << endl;
  37. cout << SegmentsAreParallel(p1, p8, p9) << endl;
  38. cout << SegmentsAreParallel(p1, p6, p9) << endl;
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
1
1
0
1
1
0