题解 | #统计字符#

统计字符

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

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main() {
    string text;
    while (getline(cin, text)) { // 注意 while 处理多个 case
        int a = 0, b = 0, c = 0, d = 0;
        for (const char ch : text) {
            if (isalpha(ch)) {
                a++;
            } else if (1 == isblank(ch)) {
                b++;
            } else if (1 == isdigit(ch)) {
                c++;
            } else {
                d++;
            }
        }
        cout << a << endl << b << endl << c << endl << d << endl;
    }
}

全部评论

相关推荐

机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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