Advertisement
Qpel

ED2 2.Plokštumoje yra daug atkarpų, kurių galų taškų

Jan 8th, 2018
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.64 KB | None | 0 0
  1. Input.txt  
  2.  
  3. 1 3 5 9
  4. 2 4 7 1
  5. -1 2 -4 5
  6. -4 4 -7 1
  7. -3 -1 -7 -5
  8. -2 -3 -1 -4
  9. 3 -2 5 -1
  10. 6 -4 7 -2
  11.  
  12.  
  13. def ilgis (x1,y1,x2,y2)
  14.   ilgis=((x2-x1)**2+(y2-y1)**2)**0.5
  15. end
  16. puts "Treciojo ketvircio atkarpu ilgiai:"
  17. fp=File.open("input.txt", "r")
  18. x,y=[]
  19. j=0
  20. suma=0
  21. k=0
  22. fp.each do |item|
  23. c =item.split(" ")
  24. for i in 0..c.length do
  25. x1=c[0].to_i
  26. y1=c[1].to_i
  27. x2=c[2].to_i
  28. y2=c[3].to_i
  29. end
  30. a=ilgis(x1,y1,x2,y2)
  31. j+=1
  32.   if (x1<0) and (y1<0)and (x2<0) and (y2<0) then
  33.     suma=suma+a
  34.     k=k+1
  35.     puts "#{sprintf('%.3f',a)}"
  36.   end
  37. end
  38. vid=suma/k
  39. puts "\n"
  40. puts "Treciojo ketvircio atkarpu ilgiu vidurkis #{sprintf('%.3f',vid)}"
  41. fp.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement