题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
package main import ( "fmt" ) func isDigit(ch byte) bool { return '0' <= ch && ch <= '9' } func transString(s string) string { var bs []byte right := 0 for right < len(s) { if !isDigit(s[right]) { bs = append(bs, s[right]) right++ continue } bs = append(bs, '*') for right < len(s) && isDigit(s[right]) { bs = append(bs, s[right]) right++ } bs = append(bs, '*') } return string(bs) } func main() { var s string fmt.Scan(&s) fmt.Println(transString(s)) }
// 本题输入为一个字符串,所以采用:fmt.Scan(&s)