计算字符串最后一个单词的长度,单词以空格隔开。
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
b := scanner.Text()
a := len(b) - strings.LastIndex(b, " ") - 1
fmt.Println(a)
}
}
转载:https://blog.csdn.net/weixin_43753680/article/details/115703255
查看评论