Files
  • main.go
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var ip string
	fmt.Println("How many strings you want to test?")
	fmt.Scanf("%d\n", &n)
	strSlice := make([]string, 0)
	for i := 0; i < n; i++ {

		fmt.Printf("Enter %d string\n", i+1)
		fmt.Scanf("%s\n", &ip)
		ip := strings.ToLower(ip)
		strSlice = append(strSlice, ip)
	}
	for _, v := range strSlice {
		fmt.Println(isP(v))
	}
}
func isP(s string) string {

	mid := len(s) / 2
	last := len(s) - 1
	for i := 0; i < mid; i++ {
		if s[i] != s[last-i] {
			return "NO. " + s + " is Not a Palindrome"
		}
	}
	return "YES. " + s + " is a Palindrome"
}
go version go1.9.4 linux/amd64