Advertisement
Guest User

glupi zadatak

a guest
May 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. struct da{
  7. float x1;
  8. float y1;
  9. float x2;
  10. float y2;
  11. float vl;
  12. }point[100];
  13.  
  14. float formula(int i){
  15. float c=sqrt(fabs((point[i].y1-point[i].y2)*(point[i].y1-point[i].y2)+(point[i].x1-point[i].x2)*(point[i].x1-point[i].x2)));
  16. return c;
  17. }
  18. void sort(int N){
  19. da ne;
  20. for(int i=N-1;i>=0;i--){
  21. for(int j=0;j<i;j++){
  22. if(point[j].vl>point[i].vl){
  23. ne=point[i];
  24. point[i]=point[j];
  25. point[j]=ne;
  26. }
  27. }
  28. }
  29. }
  30.  
  31. int main(){
  32. int N;
  33. cin>>N;
  34. for(int i=0;i<N;i++){
  35. cin>>point[i].x1;
  36. cin>>point[i].y1;
  37. cin>>point[i].x2;
  38. cin>>point[i].y2;
  39. }
  40. cout<<"\n";
  41. for(int i=0;i<N;i++){
  42. point[i].vl=formula(i);
  43. }
  44. sort(N);
  45. for(int i=0;i<N;i++){
  46. cout<<point[i].x1<<" "<<point[i].y1<<"\n"<<point[i].x2<<" "<<point[i].y2<<" "<<point[i].vl<<endl;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement