Skip to content

Commit ef10e1e

Browse files
authored
Add solutions for challenge 1 and 2 by jersonzc (#58)
* feat: add solution for challenge 1 * feat: add solution for challenge 2
1 parent d53f1a4 commit ef10e1e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
var a, b int
9+
// Read two integers from standard input
10+
_, err := fmt.Scanf("%d, %d", &a, &b)
11+
if err != nil {
12+
fmt.Println("Error reading input:", err)
13+
return
14+
}
15+
16+
// Call the Sum function and print the result
17+
result := Sum(a, b)
18+
fmt.Println(result)
19+
}
20+
21+
// Sum returns the sum of a and b.
22+
func Sum(a int, b int) int {
23+
return a + b
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strings"
8+
)
9+
10+
func main() {
11+
// Read input from standard input
12+
scanner := bufio.NewScanner(os.Stdin)
13+
if scanner.Scan() {
14+
input := scanner.Text()
15+
16+
// Call the ReverseString function
17+
output := ReverseString(input)
18+
19+
// Print the result
20+
fmt.Println(output)
21+
}
22+
}
23+
24+
// ReverseString returns the reversed string of s.
25+
func ReverseString(s string) string {
26+
var result strings.Builder
27+
for i := len(s) - 1; i >= 0; i-- {
28+
result.WriteByte(s[i])
29+
}
30+
return result.String()
31+
}

0 commit comments

Comments
 (0)