Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2357 from Freshield/master
Browse files Browse the repository at this point in the history
Fix: 修正markdown中的tab为空格,排除显示的问题
  • Loading branch information
youngyangyang04 committed Dec 9, 2023
2 parents 9615a2e + 3427281 commit 937de64
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions problems/kama54.替换数字.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,45 +190,45 @@ package main
import "fmt"

func replaceNumber(strByte []byte) string {
// 查看有多少字符
numCount, oldSize := 0, len(strByte)
for i := 0; i < len(strByte); i++ {
if (strByte[i] <= '9') && (strByte[i] >= '0') {
numCount ++
}
}
// 增加长度
for i := 0; i < numCount; i++ {
strByte = append(strByte, []byte(" ")...)
}
tmpBytes := []byte("number")
// 双指针从后遍历
leftP, rightP := oldSize-1, len(strByte)-1
for leftP < rightP {
rightShift := 1
// 如果是数字则加入number
if (strByte[leftP] <= '9') && (strByte[leftP] >= '0') {
for i, tmpByte := range tmpBytes {
strByte[rightP-len(tmpBytes)+i+1] = tmpByte
}
rightShift = len(tmpBytes)
} else {
strByte[rightP] = strByte[leftP]
}
// 更新指针
rightP -= rightShift
leftP -= 1
}
return string(strByte)
// 查看有多少字符
numCount, oldSize := 0, len(strByte)
for i := 0; i < len(strByte); i++ {
if (strByte[i] <= '9') && (strByte[i] >= '0') {
numCount ++
}
}
// 增加长度
for i := 0; i < numCount; i++ {
strByte = append(strByte, []byte(" ")...)
}
tmpBytes := []byte("number")
// 双指针从后遍历
leftP, rightP := oldSize-1, len(strByte)-1
for leftP < rightP {
rightShift := 1
// 如果是数字则加入number
if (strByte[leftP] <= '9') && (strByte[leftP] >= '0') {
for i, tmpByte := range tmpBytes {
strByte[rightP-len(tmpBytes)+i+1] = tmpByte
}
rightShift = len(tmpBytes)
} else {
strByte[rightP] = strByte[leftP]
}
// 更新指针
rightP -= rightShift
leftP -= 1
}
return string(strByte)
}

func main(){
var strByte []byte
fmt.Scanln(&strByte)

var strByte []byte
fmt.Scanln(&strByte)
newString := replaceNumber(strByte)

fmt.Println(newString)
fmt.Println(newString)
}
````

Expand Down

0 comments on commit 937de64

Please sign in to comment.