题解 | #统计字符#

统计字符

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

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    string s;
    while (getline(cin, s)) { // 注意 while 处理多个 case
        vector<int> ans(4, 0);
        for (char c : s) {
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
                ans[0]++;
            } else if (c == ' ') {
                ans[1]++;
            } else if (c >= '0' && c <= '9') {
                ans[2]++;
            } else {
                ans[3]++;
            }
        }

        for(auto i : ans)
        {
            cout << i << endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

鲁大牛:第一次美团笔试因为用豆包没做出来。第二次笔试之前重金充了一个gpt5pro的会员。结果第二次不考ai算法题了
投递美团等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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