📅  最后修改于: 2022-03-11 15:04:28.294000             🧑  作者: Mango
package main
import (
"fmt"
"math"
)
func getTimes(s string) int64 {
vowels := make(map[string]int)
for i := 1; i <= 26; i++ {
str := 64 + i
vowels[string(str)] = i - 1
}
a := float64(vowels["A"])
b := float64(vowels[string(s[0])])
numb := math.Min(math.Abs(a-b), 26-math.Abs(a-b))
for i := 1; i < len(s); i++ {
str1 := float64(vowels[string(s[i])])
str2 := float64(vowels[string(s[i-1])])
result := math.Abs(str1 - str2)
if result > 13 {
numb += 26 - result
} else {
numb += result
}
}
return int64(numb)
}
func main() {
records := getTimes("AZGB")
fmt.Println(records)
}