Golang array Inversion

Source: Internet
Author: User

I do Hackerearth on the topic record, the specific title description is this:

Given the size and the elements of array A, print all the elements in reverse order.

Input:
First line of input contains, n-size of the array.
Following N lines, each contains one integer, i{th} element of the array i.e. a[i].

Output:
Print all the elements of the array in reverse order with each element in a new line.

Constraints:

    • 1 & #x2264; N & #x2264; " >1≤n≤< Span id= "mjxc-node-39" class= "mjx-mn mjxc-space3" >1001≤n≤100
    • 0≤A[i]≤

Input

54127159


Output
9
15
7
12
4
The above is a test case:
Here is the Golang code

Package Main

Import "FMT"

Func Main () {

var inputcount int
Fmt. SCANLN (&inputcount)
var arr= make ([]int,inputcount,inputcount)
For i:=0;i<inputcount;i++{
Fmt. SCANLN (&arr[i])
}

For i:= inputCount-1; i>=0;i--{
Fmt. Println (Arr[i])
}

}

Fmt. Scanln is to get the input of the first line and assign it to the variable inputcount,Inputcount is the number of input numbers, down to create an equal-sized slice to traverse the input values and store
It's easier to get down, just invert the array output
Fmt. Scanln found in some learning algorithms of the site Hackerrank,hackerearth used quite a lot. Down is to contact the algorithm of children's shoes can go to the two sites to learn

Golang array Inversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.