-
Notifications
You must be signed in to change notification settings - Fork 2
/
SPCANDY.rb
59 lines (43 loc) · 2.08 KB
/
SPCANDY.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
# Cyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests.
# Then, if they get good marks she will reward them with candies :) However, she knows they are all very good at Mathematics, so she decided to split the candies evenly to all the students she considers worth of receiving them, so they don't fight with each other.
# She has a bag which initially contains N candies and she intends to split the candies evenly to K students. To do this she will proceed as follows: while she has more than K candies she will give exactly 1 candy to each student until she has less than K candies. On this situation, as she can't split candies equally among all students she will keep the remaining candies to herself.
# Your job is to tell how many candies will each student and the teacher
# receive after the splitting is performed.
# Input
# The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
# Each test case will consist of 2 space separated integers, N and K denoting the number of candies and the number of students as described above.
# Output
# For each test case, output a single line containing two space separated integers, the first one being the number of candies each student will get, followed by the number of candies the teacher will get.
# Constraints
# T<=100 in each test file
# 0 <= N,K <= 233 - 1
# Example
# Input:
# 2
# 10 2
# 100 3
# Output:
# 5 0
# 33 1
# Explanation
# For the first test case, all students can get an equal number of candies and teacher receives no candies at all
# For the second test case, teacher can give 33 candies to each student and keep 1 candy to herself
#!/usr/bin/ruby
t = Integer(gets.chomp)
while t != 0
t = t - 1
value =gets.chomp
n = value.split(" ").first.to_i
k = value.split(" ").last.to_i
if n == 0 && k == 0
puts "0 0"
elsif n == k
puts "1 0"
elsif n > k
r = n % k
q = n / k
puts "#{q} #{r}"
else
puts "0 #{k}"
end
end