We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e178b1d commit 5aeb501Copy full SHA for 5aeb501
Text/reverse.go
@@ -0,0 +1,36 @@
1
+package main
2
+
3
+import (
4
+ "fmt"
5
+ "os"
6
+ "bufio"
7
+ "unicode/utf8"
8
+ "strings"
9
+)
10
11
+func main() {
12
+ reader := bufio.NewReader(os.Stdin)
13
+ for {
14
+ line, err := reader.ReadString('\n')
15
16
+ if err != nil {
17
+ break
18
+ }
19
+ line = strings.TrimRight(line, "\r\n")
20
+ fmt.Println(reverseString(line));
21
22
+}
23
24
+func reverseString(source string) string {
25
+ ret := make([]rune, len(source))
26
+ i := len(source)
27
28
+ for _, c := range source {
29
+ if c != utf8.RuneError {
30
+ i--
31
+ ret[i] = c
32
33
34
35
+ return string(ret[i:])
36
0 commit comments