Skip to content

Commit 5c58adc

Browse files
Add solution for Challenge 17
1 parent 26a0c8a commit 5c58adc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

challenge-17/submissions/hvijaycse/solution-template.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
package main
22

33
import (
4+
"bufio"
45
"fmt"
6+
"os"
7+
"strings"
58
"unicode"
69
)
710

811
func main() {
912
// Get input from the user
10-
var input string
13+
reader := bufio.NewReader(os.Stdin)
1114
fmt.Print("Enter a string to check if it's a palindrome: ")
12-
fmt.Scanln(&input)
15+
input, err := reader.ReadString('\n')
16+
if err != nil {
17+
fmt.Println("Failed to read input:", err)
18+
return
19+
}
20+
input = strings.TrimSpace(input)
1321

1422
// Call the IsPalindrome function and print the result
1523
result := IsPalindrome(input)
@@ -20,7 +28,6 @@ func main() {
2028
}
2129
}
2230

23-
2431
// IsPalindrome checks if a string is a palindrome.
2532
// A palindrome reads the same backward as forward, ignoring case, spaces, and punctuation.
2633
func IsPalindrome(s string) bool {
@@ -51,4 +58,4 @@ func IsPalindrome(s string) bool {
5158

5259
}
5360
return true
54-
}
61+
}

0 commit comments

Comments
 (0)