标签:比较 == main 最小值 cts ack amp ecs 最小
问题:package main
import (
"fmt"
"strconv"
)
func reverse(s string)string{
n := len(s)
var sliRev []byte
for i:=n-1;i>=0;i--{
sliRev = append(sliRev, s[i])
}
return string(sliRev)
}
func judge(in int)bool{
decStr := strconv.Itoa(in)
octStr := fmt.Sprintf("%o", in)
binStr := fmt.Sprintf("%b", in)
decStrRev := reverse(decStr)
octStrRev := reverse(octStr)
binStrRev := reverse(binStr)
return decStr == decStrRev && octStr == octStrRev && binStr == binStrRev
}
func main(){
for i:=11;i<1000;i+=2{
if judge(i){
fmt.Println(i, "is palindromic.")
}
}
}
这是比较麻烦的方法:
标签:比较 == main 最小值 cts ack amp ecs 最小
原文地址:http://blog.51cto.com/johnnyloo/2134813