fork(10) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class tabela
  6. {
  7. public:
  8. string napis;
  9. int x,y;
  10. double odleglosc;
  11. };
  12.  
  13. void wczytaj(tabela *tab, int liczby);
  14. void quicksort(tabela *tab, int lewy, int prawy);
  15.  
  16.  
  17. int t; //liczba testów
  18. int ile; //liczba współrzędnych
  19.  
  20. int main()
  21. {
  22. ios_base::sync_with_stdio(0);
  23. cin>>t;
  24. for (int test=1; test<=t; test++) {
  25. ios_base::sync_with_stdio(0);
  26. cin >> ile;
  27. tabela * tab;
  28. tab = new tabela [ile+1];
  29. wczytaj(tab,ile);
  30. quicksort(tab,0,ile-1);
  31.  
  32. for (int i=0; i<ile; i++) {
  33. cout << tab[i].napis << " " << tab[i].x << " "<< tab[i].y;
  34. if (i!=ile-1) {
  35. cout << endl;
  36. }
  37. }
  38. if (test!=t) {
  39. cout << endl;
  40. }
  41. delete [] tab;
  42. }
  43. return 0;
  44. }
  45.  
  46. void wczytaj(tabela *tab, int liczby) {
  47.  
  48. int a,b;
  49. string nazwa;
  50. for (int i=0; i<liczby; i++) {
  51. ios_base::sync_with_stdio(0);
  52. cin >> nazwa >> a >> b;
  53. tab[i].napis = nazwa;
  54. tab[i].x = a;
  55. tab[i].y = b;
  56. tab[i].odleglosc = (a*a+b*b);
  57. }
  58. cout << endl;
  59. }
  60.  
  61. void quicksort(tabela *tab, int lewy, int prawy) {
  62. int v=(lewy+prawy)/2;
  63. int i,j;
  64. i=lewy;
  65. j=prawy;
  66. do
  67. {
  68. while(tab[i].odleglosc<tab[v].odleglosc) i++;
  69. while(tab[j].odleglosc>tab[v].odleglosc) j--;
  70. if(i<=j)
  71. {
  72. tab[ile]=tab[i];
  73. tab[i]=tab[j];
  74. tab[j]=tab[ile];
  75. i++;
  76. j--;
  77. }
  78. }
  79. while(i<=j);
  80. if(j>lewy) quicksort(tab,lewy, j);
  81. if(i<prawy) quicksort(tab, i, prawy);
  82. }
  83.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Standard output is empty