# Introduction

This time, we will create a part-time salary calculation program from standard input.

``````The salary is determined by the following rules.

・ From 9:00 to 17:00:Hourly wage X yen(Normal hourly wage)
・ From 17:00 to 22:00:Hourly wage Y yen(Night hourly wage)
・ Other times:Hourly wage Z yen(Midnight hourly wage)

Your N-day attendance and departure times are given on an hourly basis.
Calculate the total amount you will get for N days.

In the case of the input example, I work evenly in the time zone where the hourly wage is X yen, Y yen, and Z yen in 4 days.
The total amount is Z × 9+ X×8 + Y×5 + Z×1 = 1500×9 + 1000×8 + 1300×5 + 1500×1 =It will be 29500 yen.
``````
``````Input example
1000 1300 1500
4
0 9
9 17
17 22
22 23
``````
``````Output example

29500
``````

# Source

#### `ruby.rb`

``````
m = gets.split.map &:to_i
#Acquisition of self-sufficiency
nums = gets.to_i
#Obtaining the number of working days

times = []
while time = gets
times << time.chomp.split(' ').map(&:to_i)
end

sum=0
(0..nums-1).each do |i|
(times[i]+1..times[i]).each do |t|

if t<=9
sum += m
elsif t<=17
sum+= m
elsif t<=22
sum+= m
else
sum+= m
end
end
end

puts sum
``````

# Commentary

#### `ruby.rb`

``````
times = []
while time = gets
times << time.chomp.split(' ').map(&:to_i)
end
``````

Acquire multiple elements of multiple lines (working hours after the third line). By setting while time = gets, it will be repeated until all the standard input values are acquired.

#### `ruby.rb`

``````
sum=0
(0..nums-1).each do |i|
(times[i]+1..times[i]).each do |t|

#Hourly wage calculation processing

end
end
``````

#### `ruby.rb`

``````
(0..nums-1).each do |i|

#When you retrieve the i variable
# ０ １ ２ ３
``````

Get the number of work days one by one with i variable

#### `ruby.rb`

``````
(times[i]+1..times[i]).each do |t|

#When you take out the t variable(First day)
# 1 2 3 4 5 6 7 8 9
``````

1 Get the sunrise work time zone with the t variable

• In the example, this is repeated for 4 days

#### `ruby.rb`

``````
if t<=9
sum += m
elsif t<=17
sum+= m
elsif t<=22
sum+= m
else
sum+= m
end
``````

The hourly self-sufficiency acquired by the t variable in the if statement is repeatedly taken out and assigned to the sum variable.

For example, after repeating for 4 days, the sum variable is output and the total amount is calculated! !! This completes the program.

# Finally

I have a program, but I think there are many corrections. I would appreciate it if you could point out what is wrong.