File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
challenge-2/submissions/mick4711 Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "bufio"
5+ "fmt"
6+ "os"
7+ )
8+
9+ func main () {
10+ // Read input from standard input
11+ scanner := bufio .NewScanner (os .Stdin )
12+ if scanner .Scan () {
13+ input := scanner .Text ()
14+
15+ // Call the ReverseString function
16+ output := ReverseString (input )
17+
18+ // Print the result
19+ fmt .Println (output )
20+ }
21+ }
22+
23+ // ReverseString returns the reversed string of s.
24+ func ReverseString (s string ) string {
25+ // check len contraint
26+ if len (s ) > 1000 {
27+ return "input string exceeds length limit (1000)"
28+ }
29+
30+ // convert to slice of runes
31+ r := []rune (s )
32+ l := len (r )
33+
34+ // swap in place
35+ for i := 0 ; i < l / 2 ; i ++ {
36+ r [i ], r [l - i - 1 ] = r [l - i - 1 ], r [i ]
37+ }
38+
39+ // // make a slice for the result
40+ // res := make([]rune, l)
41+
42+ // // fill result from the end backwards
43+ // for i, c := range r {
44+ // res[l-i-1] = c
45+ // }
46+
47+ return string (r )
48+ }
You can’t perform that action at this time.
0 commit comments