题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

package main

import (
	"bufio"
	"fmt"
	"os"
	"unicode"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	b, _, _ := reader.ReadLine()
	str := string(b)
	var letter, space, number, other int
	for _, s := range str {
		if unicode.IsLetter(s) {
			letter++
			continue
		}
		if unicode.IsSpace(s) {
			space++
			continue
		}
		if unicode.IsNumber(s) {
			number++
			continue
		}
		other++
	}
	fmt.Printf("%d\n%d\n%d\n%d", letter, space, number, other)
}

全部评论

相关推荐

06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务