题解 | 统计字符

统计字符

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

package main

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

func main() {
	scan := bufio.NewScanner(os.Stdin)
	scan.Scan()
	input := scan.Text()
	chNum := 0
	spaceNum := 0
	numberNum := 0
	otherNum := 0
	for _, ch := range input {
		if unicode.IsLetter(unicode.ToLower(ch)) {
			chNum++
		} else if unicode.IsDigit(ch) {
			numberNum++
		} else if ch == 32 {
			spaceNum++
		} else {
			otherNum++
		}
	}
	fmt.Println(chNum)
	fmt.Println(spaceNum)
	fmt.Println(numberNum)
	fmt.Println(otherNum)
}

全部评论

相关推荐

10-16 23:37
已编辑
门头沟学院 运营
据说名字越长别人越关...:西交做运营吗。。就业市场已经颠了
简历被挂麻了,求建议
点赞 评论 收藏
分享
gelmanspar...:奖学金删掉,自我评价删掉,简历压缩一下,写一页
如果再来一次,你还会学机...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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