Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Input.txt
- 1 3 5 9
- 2 4 7 1
- -1 2 -4 5
- -4 4 -7 1
- -3 -1 -7 -5
- -2 -3 -1 -4
- 3 -2 5 -1
- 6 -4 7 -2
- def ilgis (x1,y1,x2,y2)
- ilgis=((x2-x1)**2+(y2-y1)**2)**0.5
- end
- puts "Treciojo ketvircio atkarpu ilgiai:"
- fp=File.open("input.txt", "r")
- x,y=[]
- j=0
- suma=0
- k=0
- fp.each do |item|
- c =item.split(" ")
- for i in 0..c.length do
- x1=c[0].to_i
- y1=c[1].to_i
- x2=c[2].to_i
- y2=c[3].to_i
- end
- a=ilgis(x1,y1,x2,y2)
- j+=1
- if (x1<0) and (y1<0)and (x2<0) and (y2<0) then
- suma=suma+a
- k=k+1
- puts "#{sprintf('%.3f',a)}"
- end
- end
- vid=suma/k
- puts "\n"
- puts "Treciojo ketvircio atkarpu ilgiu vidurkis #{sprintf('%.3f',vid)}"
- fp.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement