Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cmath>
- using namespace std;
- struct Coord
- {
- int x, y;
- };
- Coord pct[100];
- int n;
- inline void Citire()
- {
- ifstream fin("puncte.in");
- fin >> n;
- for(int i = 0; i < n; i++)
- fin >> pct[i].x >> pct[i].y;
- fin.close();
- }
- ofstream fout("puncte.out");
- inline double DistPct(Coord a, Coord b)
- {
- return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
- }
- double MinDist()
- {
- int i, j;
- double d, mind = DistPct(pct[0], pct[1]);
- for(i = 0; i < n-1; i++)
- for(j = i+1; j < n; j++)
- {
- d = DistPct(pct[i], pct[j]);
- if(d < mind) mind = d;
- }
- return mind;
- }
- void Afisare()
- {
- fout << "\nPunctele ordonate: \n";
- for(int i = 0; i < n; i++)
- fout << pct[i].x << " " << pct[i].y << "\n";
- }
- void Ord()
- {
- int i, j;
- Coord aux;
- for(i = 0; i < n-1; i++)
- for(j = i+1; j < n; j++)
- {
- if(pct[i].y > pct[j].y)
- {
- aux = pct[i];
- pct[i] = pct[j];
- pct[j] = aux;
- }
- else if((pct[i].y == pct[j].y) && (pct[i].x > pct[j].x))
- {
- aux = pct[i];
- pct[i] = pct[j];
- pct[j] = aux;
- }
- }
- Afisare();
- }
- int main()
- {
- Citire();
- fout << "Distanta minima dintre 2 pct: " << MinDist() << "\n";
- Ord();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement