华为机试-统计字符(中等)

统计字符

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

题目描述

输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。

#include<iostream>
using namespace std;
int main(){
    string s;
    while(getline(cin,s)){
        int num_letter=0,num_block=0,num_num=0,num_other=0;
        for(auto i:s){
            if(i>='a'&&i<='z')
                num_letter++;
            else if(i==' ')
                num_block++;
            else if(i>='0'&&i<='9')
                num_num++;
            else
                num_other++;
        }
        cout<<num_letter<<endl<<num_block<<endl<<num_num<<endl<<num_other<<endl;
    }
}
全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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