题解 | #统计字符#

统计字符

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

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
    string str;
    getline(cin, str);
    int a = 0, b = 0, c = 0, d = 0;
    for (auto ch : str) {
        if (isalpha(ch)) {
            a++;
        } else if (ch == ' ') {
            b++;
        } else if (isdigit(ch)) {
            c++;
        } else d++;
    }
    cout << a << endl;
    cout << b << endl;
    cout << c << endl;
    cout << d << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

菠落蜜:这个是系统自动投的,不是hr主动打招呼。更抽象的还有ai回复
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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