1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| package main
import "fmt"
func replaceDigits(s []byte) string { numCount := 0 for _, c := range s { if c >= '0' && c <= '9' { numCount++ } } result := make([]byte, 0, len(s)+5*numCount)
for i := 0; i < len(s); i++ { c := s[i] if c >= '0' && c <= '9' { result = append(result, []byte("number")...) } else { result = append(result, c) } } return string(result) }
func main() { var strByte []byte fmt.Scanln(&strByte) newString := replaceDigits(strByte) fmt.Println(newString) }
|