fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. class Punkt
  8. {
  9. string nazwa;
  10. int x,y;
  11. public:
  12. void wczytaj()
  13. {
  14. cin>>nazwa>>x>>y;
  15. }
  16. void wypisz()
  17. {
  18. cout<<nazwa<<" "<<x<<" "<<y<<endl;
  19. }
  20. bool operator < (const Punkt &a)const
  21. {
  22. return sqrt(pow(x,2)+pow(y,2)) < sqrt(pow(a.x,2)+pow(a.y,2));
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. short test,ile;
  29. cin>>test;
  30. while(test--)
  31. {
  32. cin>>ile;
  33. Punkt p[ile];
  34. for(int i=0; i<ile; i++)
  35. {
  36. p[i].wczytaj();
  37. }
  38. sort(p,p+ile);
  39. for(int i=0; i<ile; i++)
  40. {
  41. p[i].wypisz();
  42. }
  43. cout<<endl;
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 4400KB
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