题解 | #名字的漂亮度#
名字的漂亮度
https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3
package main import ( "fmt" "bufio" "os" "strings" "sort" ) func beatifulDegree(s string)int{ res := 0 var m = make(map[rune]int) var list = make([]int,0,len(s)) for _,c :=range s{ m[c] = strings.Count(s,string(c)) } for _,v := range m{ list = append(list,v) } sort.Sort(sort.Reverse(sort.IntSlice(list))) for i:=0;i<len(list);i++{ res += (26-i)*list[i] } return res } func main() { var n int fmt.Scan(&n) sc:=bufio.NewScanner(os.Stdin) for ;n>0;n--{ sc.Scan() s := sc.Text() s= strings.ToLower(s) fmt.Println(beatifulDegree(s)) } }