Habsburg

ZD3

May 14th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. struct tocka {
  6.     string ime;
  7.     float X, Y, R;
  8. };
  9.  
  10. int main() {
  11.     int N;
  12.     do {
  13.         cout << "N: ";
  14.         cin >> N;
  15.     }while(N <= 0);
  16.     tocka polje[N];                                        
  17.     for(int i = 0; i < N; i++) {
  18.         cout << "Ime tocke: ";
  19.         cin >> polje[i].ime;
  20.         cout << "X: ";
  21.         cin >> polje[i].X;
  22.         cout << "Y: ";
  23.         cin >> polje[i].Y;
  24.        
  25.         polje[i].R = sqrt( (polje[i].X - 0) * (polje[i].X - 0) + (polje[i].Y - 0) * (polje[i].Y - 0)); // Formula za izračun udaljenosti između dvije točke
  26.        
  27.     }
  28.     bool found = true;
  29.     while(found) {      //BubleSort. Petlja while traje sve dok nema više zamjena
  30.         found = false;
  31.         for(int i = 0; i < N-1; i++) {
  32.             if(polje[i].R < polje[i+1].R) {
  33.                 swap(polje[i], polje[i+1]);
  34.                 found = true;
  35.             }
  36.         }
  37.     }
  38.    
  39.     for(int i = 0; i < N; i++) {
  40.         cout << polje[i].ime << endl;
  41.     }
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment