题解 | #句子逆序##GOLANG#通过栈实现
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
package main import ( "fmt" "io" ) func main() { //使用压入栈的方法 words := make([]string, 0) for { temp := "" _, err := fmt.Scanf("%s", &temp) if err == io.EOF { break } words = append(words, temp) } for i := len(words) - 1; i >= 0; i-- { if len(words) - 1 == i{ fmt.Printf("%s",words[i]) continue } fmt.Printf(" %s",words[i]) } }