Created
May 12, 2019 21:06
-
-
Save stek29/a06e630473b1fd6af091f47577efe37d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"strings" | |
"github.com/rivo/uniseg" | |
) | |
func reverseStringSlice(ss []string) { | |
last := len(ss) - 1 | |
for i := 0; i < len(ss)/2; i++ { | |
ss[i], ss[last-i] = ss[last-i], ss[i] | |
} | |
} | |
func unicodeReverse(in string) string { | |
var chunks []string | |
gr := uniseg.NewGraphemes(in) | |
for gr.Next() { | |
chunks = append(chunks, gr.Str()) | |
} | |
reverseStringSlice(chunks) | |
return strings.Join(chunks, "") | |
} | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
fmt.Println(unicodeReverse(scanner.Text())) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment