1 Star 0 Fork 53

fflush / c2go

forked from Apocalypse / c2go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
7.go 679 Bytes
一键复制 编辑 原始数据 按行查看 历史
ZenQy 提交于 2015-03-29 18:12 . last push
//输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
letters, space, digit, others := 0, 0, 0, 0
fmt.Println("Please input some characters:")
inputReader := bufio.NewReader(os.Stdin)
str, _ := inputReader.ReadString('\n')
fmt.Println(str)
s := []byte(str)
for _, n := range s {
if n >= byte('a') && n <= byte('z') {
letters += 1
} else if n >= byte('0') && n <= byte('9') {
digit += 1
} else if n == byte(' ') {
space += 1
} else {
others += 1
}
}
fmt.Println("letters:", letters, "\tspace:", space, "\tdigit:", digit, "\tothers:", others)
}
Go
1
https://gitee.com/fflush/c2go.git
git@gitee.com:fflush/c2go.git
fflush
c2go
c2go
master

搜索帮助