题解 | #字符统计#
字符统计
http://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
package main
import (
"fmt"
"os"
"bufio"
"sort"
)
func main() {
input := bufio.NewScanner(os.Stdin)
for input.Scan() {
text := input.Text()
map1 := map[byte]int{}
bytes := []byte{}
for i := range text {
if _, ok := map1[text[i]]; !ok {
bytes = append(bytes, text[i])
}
map1[text[i]]++
}
sort.Slice(bytes, func(i, j int) bool {
if map1[bytes[i]] == map1[bytes[j]] {
return bytes[i] < bytes[j]
}
return map1[bytes[i]] > map1[bytes[j]]
})
fmt.Println(string(bytes))
}
}
三奇智元机器人科技有限公司公司福利 70人发布