fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct punkt
  6. {
  7. float x, y;
  8. };
  9.  
  10. // funkcja wpisująca współrzędne do struktury
  11. void wczytaj_punkt(punkt &p, float x, float y)
  12. {
  13. p.x = x;
  14. p.y = y;
  15. }
  16.  
  17. // funkcja sprawdzająca czy punkty są po tej samej stronie prostej
  18. bool po_tej_samej_stronie(float A, float B, float C, punkt p1, punkt p2)
  19. {
  20. float W1 = A * p1.x + B * p1.y + C;
  21. float W2 = A * p2.x + B * p2.y + C;
  22.  
  23. // jeśli któryś punkt leży na prostej → false
  24. if (W1 == 0 || W2 == 0)
  25. return false;
  26.  
  27. return (W1 * W2 > 0);
  28. }
  29.  
  30. int main()
  31. {
  32. // ===== DANE WPISANE W KODZIE =====
  33. float A = 1, B = -1, C = 0; // prosta: x - y = 0
  34.  
  35. punkt P1, P2;
  36.  
  37. wczytaj_punkt(P1, 2, 1); // punkt 1
  38. wczytaj_punkt(P2, 5, -1); // punkt 2
  39. // =================================
  40.  
  41. if (po_tej_samej_stronie(A, B, C, P1, P2))
  42. cout << "TAK";
  43. else
  44. cout << "NIE";
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
TAK