forked from GeekBrainsTeam/free-courses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask3.rb
executable file
·62 lines (52 loc) · 981 Bytes
/
task3.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
58
59
60
61
62
# Task 3
if ARGV.length < 2
exit(1)
end
t1 = ARGV[0].to_i
t2 = ARGV[1].to_i
if t1 < 1 or t1 > 100000 or t2 < 1 or t2 > 100000
exit(1)
end
t = t1 + t2
result=""
hours = t / 3600
secs = t % 3600
mins = secs / 60
secs %= 60
if hours > 0
h0 = hours % 10
suffix = ""
if (5..9) === h0 or h0 == 0 or (11..14) === hours
suffix = "ов"
elsif (2..4) === h0
suffix = "а"
end
result = hours.to_s + " час" + suffix
end
if mins > 0
if result != ""
result += " "
end
m0 = mins % 10
suffix = "а"
if (5..9) === m0 or m0 == 0 or (11..14) === mins
suffix = ""
elsif (2..4) === m0
suffix = "ы"
end
result += mins.to_s + " минут" + suffix
end
if secs > 0
if result != ""
result += " "
end
s0 = secs % 10
suffix = "а"
if (5..9) === s0 or s0 == 0 or (11..14) === secs
suffix = ""
elsif (2..4) === s0
suffix = "ы"
end
result += secs.to_s + " секунд" + suffix
end
puts result