惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
有赞技术团队
有赞技术团队
罗磊的独立博客
博客园 - 叶小钗
Jina AI
Jina AI
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
量子位
MyScale Blog
MyScale Blog
V
Visual Studio Blog
博客园 - 聂微东
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
小众软件
小众软件
宝玉的分享
宝玉的分享

博客园 - 留云

dotnet core 自定义配置文件 Dotnet Core Windows Service golang 用tar打包文件或文件夹 golang 最和谐的子序列 golang 轮训加密算法 golang map golang 队列 golang 栈操作 golang 多维数组 nginx 在windows平台上对asp.net做反向代理 - 留云 树形结构应用技巧 用批命令更新数据库 c# 中Exception 的重试机制 jquery 调用wcf project HTTP协议之Session和Cookie C#多线程同步 SQL优化-索引 UML在关系型数据库设计中的应用 Web 应用的 UML 建模与 .NET 框架开发
golang 数组反转
留云 · 2017-05-11 · via 博客园 - 留云

我做hackerearth上题目记录,具体的题目描述是这样的:

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, each element in a new line.

Constraints:

    • 1N1001≤N≤100
    • 0A[i]1000

 输入

5
4
12
7
15
9

输出
9
15
7
12
4

上面就是个测试用例:
下面是golang代码

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 是获取第一行的输入并赋值给变量inputCount,inputCount 是一共输入数字的个数,下来就是创建一个同等大小的slice来遍历输入的数值并存储
下来就比较简单了,只是把数组反转输出
之前没有用过
fmt.Scanln 发现在一些学习算法的网站hackerrank,hackerearth 用的挺多的。下来就是要联系算法的童鞋可以到这两个网站上去学习