fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define all(a) (a).begin(), (a).end()
  4. #define dbg_line(x) cout << (x) << '\n'
  5. #define dbg(x) cout << x << " "
  6.  
  7. using namespace std;
  8.  
  9. // <--> Report constants <-->
  10.  
  11. typedef pair<int, int> pii;
  12. const int max_n = 1e5 + 5;
  13. const ll inf = 1e9;
  14. const ll m_inf = -1e9;
  15. const ll mod = 1e9 + 7;
  16.  
  17. // <--> Report variables <-->
  18.  
  19.  
  20. // <--> Main Code is Here <-->
  21.  
  22. class Point{
  23. private:
  24. float x, y;
  25. public:
  26. Point(){
  27.  
  28. }
  29. Point(float x, float y){
  30. this->x = x;
  31. this->y = y;
  32. }
  33. float getX(){
  34. return x;
  35. }
  36. float getY(){
  37. return y;
  38. }
  39. float distance(Point tmp){
  40. return sqrt(pow((x - tmp.getX()), 2) + pow((y - tmp.getY()), 2));
  41. }
  42. };
  43.  
  44. class Straight{
  45. private:
  46. Point x, y;
  47. public:
  48. Straight(){
  49.  
  50. }
  51. Straight(Point x, Point y){
  52. this->x = x;
  53. this->y = y;
  54. }
  55. float dist(){
  56. return x.distance(y);
  57. }
  58.  
  59. };
  60.  
  61. int main(){
  62. int n;
  63. cout << "Nhap N Duong Thang: ";
  64. cin >> n;
  65. float minDist = inf, maxDist = -inf;
  66. for (int i = 0; i < n; i++){
  67. int x1, y1, x2, y2;
  68. cout << "Nhap Toa Do Diem X: ";
  69. cin >> x1 >> y1;
  70. cout << "Nhap Toa Do Diem Y: ";
  71. cin >> x2 >> y2;
  72. Point x(x1, y1), y(x2, y2);
  73. Straight s(x, y);
  74. minDist = min(minDist, s.dist());
  75. maxDist = max(maxDist, s.dist());
  76. }
  77. cout << "Duong Thang Ngan Nhat La: " << minDist << '\n';
  78. cout << "Duong Thang Dai Nhat La: " << maxDist << '\n';
  79. }
  80.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Nhap N Duong Thang: Duong Thang Ngan Nhat La: 1e+09
Duong Thang Dai Nhat La: -1e+09