Advertisement
J00ker

Untitled

Feb 11th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <fstream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. struct Coord
  7. {
  8. int x, y;
  9. };
  10.  
  11. Coord pct[100];
  12. int n;
  13.  
  14. inline void Citire()
  15. {
  16. ifstream fin("puncte.in");
  17. fin >> n;
  18. for(int i = 0; i < n; i++)
  19. fin >> pct[i].x >> pct[i].y;
  20. fin.close();
  21. }
  22.  
  23. ofstream fout("puncte.out");
  24.  
  25. inline double DistPct(Coord a, Coord b)
  26. {
  27. return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
  28. }
  29.  
  30. double MinDist()
  31. {
  32. int i, j;
  33. double d, mind = DistPct(pct[0], pct[1]);
  34. for(i = 0; i < n-1; i++)
  35. for(j = i+1; j < n; j++)
  36. {
  37. d = DistPct(pct[i], pct[j]);
  38. if(d < mind) mind = d;
  39. }
  40. return mind;
  41. }
  42.  
  43. void Afisare()
  44. {
  45. fout << "\nPunctele ordonate: \n";
  46. for(int i = 0; i < n; i++)
  47. fout << pct[i].x << " " << pct[i].y << "\n";
  48. }
  49.  
  50. void Ord()
  51. {
  52. int i, j;
  53. Coord aux;
  54. for(i = 0; i < n-1; i++)
  55. for(j = i+1; j < n; j++)
  56. {
  57. if(pct[i].y > pct[j].y)
  58. {
  59. aux = pct[i];
  60. pct[i] = pct[j];
  61. pct[j] = aux;
  62. }
  63. else if((pct[i].y == pct[j].y) && (pct[i].x > pct[j].x))
  64. {
  65. aux = pct[i];
  66. pct[i] = pct[j];
  67. pct[j] = aux;
  68. }
  69. }
  70. Afisare();
  71. }
  72.  
  73. int main()
  74. {
  75. Citire();
  76. fout << "Distanta minima dintre 2 pct: " << MinDist() << "\n";
  77. Ord();
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement