fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5. struct point2D
  6. {
  7. int x;
  8. int y;
  9. };
  10. float max(float a, float b)
  11. {
  12. if (a>b)
  13. return a;
  14. else
  15. return b;
  16. }
  17. void inputPoint(vector<point2D> point)
  18. {
  19. int i;
  20. int n;
  21. point2D temp;
  22. cout << "Hay nhap so diem: ";
  23. cin >> n;
  24. point.resize(n);
  25. for (i=1;i<=(n);i++)
  26. {
  27. cout << "Hay nhap diem thu " << i << endl ;
  28. cin >> temp.x >> temp.y;
  29. point.push_back(point2D()); //emplace_back()
  30. point[i-1].x=temp.x;
  31. point[i-1].y=temp.y;
  32. }
  33. cout << "Complete";
  34. }
  35. float distance(point2D pt1, point2D pt2)
  36. {
  37. return sqrt(pow(double(pt1.x-pt2.x),2)+pow(double(pt1.y-pt2.y),2));
  38. }
  39. float findDis(vector<point2D> point)
  40. {
  41. int size=point.size();
  42. float maximum=0;
  43. int i,j;
  44. for (i=0;i<size;i++)
  45. for (j=0;j<size;i++)
  46. maximum=max(maximum,distance(point[i],point[j]));
  47. return maximum;
  48. }
  49.  
  50. int main()
  51. {
  52. vector<point2D> point;
  53. int n;
  54. inputPoint(point);
  55. cout << "Khoang cach lon nhat la: " << findDis(point);
  56. getchar();
  57. getchar();
  58. return 0;
  59. }
Success #stdin #stdout 0s 3236KB
stdin
2 1 2 3 4
stdout
Hay nhap so diem: Hay nhap diem thu 1
Hay nhap diem thu 2
CompleteKhoang cach lon nhat la: 0