This is my own output.
I did a program to calculate the calories of the food I ate.
M = number of food items N = number of people food = calories per gram eat = how many g you ate carolie = total calories
qiita.rb
M,N = gets.chomp.split(" ").map{|i| i.to_i}
food = []
i = 0
M.times do
i = (gets.to_f / 100)
food.push(i)
end
eat = []
N.times do
i = gets.chomp.split(" ").map{|i| i.to_i}
eat.push(i)
end
i = 0
f = 0
total = []
count = N
count1 = M - 1
calorie = 0
while count > 0 do
for s in 0..count1 do
calorie += (food[i] * eat[f][s]).floor
i = i + 1
end
total.push(calorie)
calorie = 0
i = 0
f = f + 1
count = count - 1
end
puts total
I'm not so used to using for sentences, so I'm glad I could use it this time. Perhaps I felt that I could condense more by using a two-dimensional array this time, but it didn't work. .. ..
Recommended Posts