Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```golang
- package main
- func reverse(str string) string {
- if len(str) == 0 || str == " " {
- return str
- }
- index := 0
- for index < len(str) && str[index] != ' ' {
- index = index + 1
- }
- if index == len(str) {
- return str
- }
- return reverse(string(str[index+1:])) + " " + string(str[0:index])
- }
- func main() {
- var str = "jiu shi ni , rang wo da ban ye bu shui jiao , zai zheli zuo timu !"
- println(str)
- println(reverse(str))
- }
- ```
- run it
- ```shell
- go run main.go
- ```
- stdout
- ```txt
- jiu shi ni , rang wo da ban ye bu shui jiao , zai zheli zuo timu !
- ! timu zuo zheli zai , jiao shui bu ye ban da wo rang , ni shi jiu
- ```
Add Comment
Please, Sign In to add comment