mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
809 B
42 lines
809 B
2 years ago
|
# ReverseSecondHalf
|
||
|
|
||
|
### Instructions
|
||
|
Write a function `ReverseSecondHalf()` that takes a string as an argument and prints the second half reversed. If the length of the string is odd, round it up.
|
||
|
|
||
|
- Prints the second half reversed followed by newline `\n`.
|
||
|
- if the string is empty, return `Invalid Output`.
|
||
|
- If the string's length equals one, return it, followed by newline `\n`.
|
||
|
|
||
|
### Expected function
|
||
|
|
||
|
```go
|
||
|
func ReverseSecondHalf(str string) string {
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
|
|
||
|
Here is a possible program to test your function:
|
||
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
ReverseSecondHalf("This is the 1st half This is the 2nd half")
|
||
|
ReverseSecondHalf("")
|
||
|
ReverseSecondHalf("Hello World")
|
||
|
}
|
||
|
```
|
||
|
|
||
|
And its output :
|
||
|
|
||
|
```go
|
||
|
$ go run . | cat -e
|
||
|
flah dn2 eht si sihT$
|
||
|
Invalid Output$
|
||
|
dlroW$
|
||
|
```
|