Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2e33887

Browse files
Merge pull request youngyangyang04#2339 from gdstzmy/master
Update 替换数字, 右旋字符串的Go语言写法
2 parents b87b2bf + 972ca2d commit 2e33887

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

‎problems/kama54.替换数字.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ class Main {
162162
```
163163

164164
### Go:
165+
````go
166+
package main
167+
168+
import "fmt"
169+
170+
func main(){
171+
var strByte []byte
172+
173+
fmt.Scanln(&strByte)
174+
175+
for i := 0; i < len(strByte); i++{
176+
if strByte[i] <= '9' && strByte[i] >= '0' {
177+
inserElement := []byte{'n','u','m','b','e','r'}
178+
strByte = append(strByte[:i], append(inserElement, strByte[i+1:]...)...)
179+
i = i + len(inserElement) -1
180+
}
181+
}
182+
183+
fmt.Printf(string(strByte))
184+
}
185+
````
165186

166187

167188

‎problems/kama55.右旋字符串.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,34 @@ public class Main {
214214

215215

216216
### Go:
217+
```go
218+
package main
219+
import "fmt"
220+
221+
func reverse (strByte []byte, l, r int){
222+
for l < r {
223+
strByte[l], strByte[r] = strByte[r], strByte[l]
224+
l++
225+
r--
226+
}
227+
}
228+
229+
230+
func main(){
231+
var str string
232+
var target int
233+
234+
fmt.Scanln(&target)
235+
fmt.Scanln(&str)
236+
strByte := []byte(str)
237+
238+
reverse(strByte, 0, len(strByte) - 1)
239+
reverse(strByte, 0, target - 1)
240+
reverse(strByte, target, len(strByte) - 1)
241+
242+
fmt.Printf(string(strByte))
243+
}
244+
```
217245

218246

219247
### JavaScript:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /