Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created April 12, 2020 20:37
Show Gist options
  • Save marti1125/e36d2d16219a690d5bf9b048bd67e642 to your computer and use it in GitHub Desktop.
Save marti1125/e36d2d16219a690d5bf9b048bd67e642 to your computer and use it in GitHub Desktop.
array
package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"strings"
)
func main() {
reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
nTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
checkError(err)
n := int32(nTemp)
arrTemp := strings.Split(readLine(reader), " ")
var arr []int32
for i := 0; i < int(n); i++ {
arrItemTemp, err := strconv.ParseInt(arrTemp[i], 10, 64)
checkError(err)
arrItem := int32(arrItemTemp)
arr = append(arr, arrItem)
}
valuesText := []string{}
for i := len(arr)-1; i >= 0; i-- {
number := arr[i]
text := strconv.Itoa(int(number))
valuesText = append(valuesText, text)
}
fmt.Println(strings.Join(valuesText, " "))
}
func readLine(reader *bufio.Reader) string {
str, _, err := reader.ReadLine()
if err == io.EOF {
return ""
}
return strings.TrimRight(string(str), "\r\n")
}
func checkError(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment