题解 | #字符逆序#

字符逆序

https://www.nowcoder.com/practice/cc57022cb4194697ac30bcb566aeb47b

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
  reader := bufio.NewReader(os.Stdin)
  str,_ := reader.ReadString('\n')
   // reader.ReadLine()
   // If the line was too long for the buffer then isPrefix is set and the beginning of the line is returned. The rest of the line will be returned from future calls. isPrefix will be false when returning the last fragment of the line. The returned buffer is only valid until the next call to ReadLine. ReadLine either returns a non-nil line or it returns an error, never both.The text returned from ReadLine does not include the line end ("\r\n" or "\n").
  line := []byte(str)
  if line[len(line)-1] == '\n' {
    line = line[:len(line)-1]
  }
  for i, j := 0, len(line)-1; i < j; i, j =i+1, j-1 {
    line[i], line[j] = line[j], line[i]
  }
  fmt.Println(string(line))
}

全部评论

相关推荐

白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务