题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
package main
import (
"bufio"
"fmt"
"os"
"unicode"
)
func main() {
reader := bufio.NewReader(os.Stdin)
res,_,_ := reader.ReadLine()
m, s, n, o := 0, 0,0,0
for _, ch := range res {
if ch = byte(unicode.ToLower(rune(ch))); ch >= 'a' && ch <= 'z' {
m++
} else if ch >= '0' && ch <= '9' {
n++
} else if ch == ' ' {
s++
} else {
o++
}
}
fmt.Printf("%d\n%d\n%d\n%d\n", m, s, n, o)
}
OPPO公司福利 547人发布