*** paiza How can I achieve Rank D ***? I explained the guideline.
Since the author is mainly learning Ruby, I will explain it in Ruby.
For example, to enter a number of your choice and output it, write the following code.
x = gets.chomp.to_i
puts x
You need to rewrite gets
a little to enter more than one number.
x = gets.split().map(&:to_i)
puts x
You can use the split
method to get multiple input values as an array.
map
You can easily convert the contents of the array using methods.
If the argument is &: to_i
, all the input values can be obtained as numerical values.
Here, if there are two input values, the difference between the first input value and the second input value can be calculated as follows.
x = gets.split().map(&:to_i)
puts x[0] -x[1]
Since x is obtained as an array, you can use the operators between the elements of the array to calculate the difference between the input values.
If you can master the above things. *** paiza Rank D *** is just around the corner.
Recommended Posts