题解 | #统计字符#__huawei_no.40-1

统计字符

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

#include <iostream>
using namespace std;

int main() {
    string str;
    getline(cin,str);
    int count_1 = 0;
    int count_2 = 0;
    int count_3 = 0;
    int count_4 = 0;
    for(char c : str){
        if ( c >= '0' && c <= '9'){
            count_3++;
        }
        else if(c >= 'A' && c <= 'Z'){
            count_1++;
        }
        else if (c >= 'a' && c <= 'z'){
            count_1++;
        }
        else if ( c == ' '){
            count_2++;
        }
        else{
            count_4++;
        }
    }
    cout << count_1<<endl;
    cout << count_2<<endl;
    cout << count_3<<endl;
    cout << count_4<<endl;
    return 0;


}
// 64 位输出请用 printf("%lld")

简单粗暴的解决

全部评论

相关推荐

迷茫的大四🐶:都收获五个了,兄弟那还说啥,不用改了,去玩吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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