题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
input := bufio.NewScanner(os.Stdin)
input.Scan()
inputs := input.Text()
word := 0
num := 0
space := 0
other := 0
for _, v := range inputs {
if v >= 'a' && v <= 'z' || v >= 'A' && v <= 'Z' {
word++
} else if v >= 48 && v <= 57 {
num++
} else if v == ' ' {
space++
} else {
other++
}
}
fmt.Println(word)
fmt.Println(space)
fmt.Println(num)
fmt.Println(other)
}
查看9道真题和解析
