题解 | #统计字符#

统计字符

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

#include<stdio.h>
#include<string.h>
int main(){
    int count_eng=0,count_kong=0,count_num=0,count_other=0;
    char str[1001]={'\0'};
    while(scanf("%[^\n]",str)>0){
        for(int i=0;i<strlen(str);i++){
           if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))
               count_eng=count_eng+1;
            else if(str[i]==' ')
                count_kong=count_kong+1;
            else if(str[i]>='0'&&str[i]<='9')
                count_num=count_num+1;
            else
               count_other=count_other+1; 
        }
    }
    printf("%d\n%d\n%d\n%d",count_eng,count_kong,count_num,count_other);
}
全部评论

相关推荐

09-28 01:10
中山大学 运营
点赞 评论 收藏
分享
10-10 01:10
已编辑
深圳大学 测试开发
面了100年面试不知...:六月到九月,四个项目一个实习,是魔丸吗
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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