-
Notifications
You must be signed in to change notification settings - Fork 0
/
2785.rb
57 lines (47 loc) · 941 Bytes
/
2785.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# @see https://codeiq.jp/q/2785
class Point
attr_accessor :x, :y
def initialize(x, y)
@x = x.to_f
@y = y.to_f
end
def distance(other)
self.class.distance self, other
end
def distance2(other)
self.class.distance2 self, other
end
def self.distance(a, b)
Math.sqrt distance2(a, b)
end
def self.distance2(a, b)
(b.x - a.x) ** 2 + (b.y - a.y) ** 2
end
end
result = ''
gets.chomp.split(' ').each do |param|
m = param.match %r{\((\d+),(\d+)\)(\d+)/\((\d+),(\d+)\)(\d+)}
a = Point.new m[1], m[2]
ar = m[3].to_f
b = Point.new m[4], m[5]
br = m[6].to_f
if a.x == b.x && a.y == b.y && ar == br
result += 'A'
next
end
d = Point.distance2(a, b)
rd1 = (ar - br) ** 2
rd2 = (ar + br) ** 2
if d < rd1
result += 'B'
elsif d == rd1
result += 'C'
elsif d < rd2
result += 'D'
elsif d == rd2
result += 'E'
else
result += 'F'
end
end
puts result