Today, we’re learning about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video!
Given an array, A, of N integers, print A’s elements in reverse order as a single line of space-separated numbers.
The first line contains an integer, N(the size of our array).
The second line contains N space-separated integers describing array A’s elements.
- 1 <= N <= 1000
- 1 <- Ai <= 10000, where Ai is the ith integer in the array.
Print the elements of array A in reverse order as a single line of space-separated numbers.
1 4 3 2
2 3 4 1
#!/bin/ruby n = gets.strip.to_i arr = gets.strip arr = arr.split(' ').map(&:to_i) count = arr.size op = "" until (count == 0) count -= 1 op += arr[count].to_s + " " end puts op