fork(6) download
  1. /*
  2. program: sorotwanie punktow
  3. date:25.10.2016
  4. author: kyubu
  5. version 2.0
  6. */
  7. #include <iostream>
  8. #include <math.h>
  9. using namespace std;
  10.  
  11. struct punkt
  12. {
  13. public:
  14. int odleglosc,x,y;
  15. string nazwa;
  16.  
  17. };
  18. int main()
  19. {
  20. int t; // liczba przypadkow
  21. cin >> t;
  22. punkt ** tablica = new punkt * [t];
  23. short * ntablica = new short [t];
  24. for(int z=0;z<t;z++)
  25. {
  26. int n; //liczba punktow
  27. cin >> n;
  28. tablica[z] = new punkt[n];
  29. ntablica[z]=n;
  30. for (int x=0;x<n;x++)
  31. {
  32. cin>>tablica[z][x].nazwa>>tablica[z][x].x>>tablica[z][x].y;
  33. tablica[z][x].odleglosc=sqrt(pow(tablica[z][x].x,2)*pow(tablica[z][x].y,2));
  34. }
  35. //sortowanie bÄ…belkowe
  36. int sort=1;
  37. while(sort>0)
  38. {
  39. sort=0;
  40. for (int x=0;x<n;x++)
  41. {
  42. if(tablica[z][x].odleglosc>tablica[z][x+1].odleglosc)
  43. {
  44. punkt temp;
  45. temp=tablica[z][x];
  46. tablica[z][x]=tablica[z][x+1];
  47. tablica[z][x+1]=temp;
  48. sort++;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. //prezentacja
  55. for(int z=0;z<t;z++)
  56. {
  57. for (int x=0;x<ntablica[z];x++) cout<<tablica[z][x].nazwa<<' '<<tablica[z][x].x<<' '<<tablica[z][x].y<<endl;
  58. cout<<endl;
  59. }
  60. return 0;
  61. }
  62.  
Success #stdin #stdout 0s 3476KB
stdin
2
3
A 0 0
C 5 5
B 1 -1

1
X 1 1
stdout
A 0 0
B 1 -1
C 5 5

X 1 1