题解 | #统计字符#

统计字符

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")

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 19:30
化身华黑&nbsp;今天询问对接人审批情况,结果被告知没HC了&nbsp;云计算&nbsp;
苦闷的柠檬精allin实习:主管面结束后hr每周保温一次,结果前几天和我说没hc了,我也化身华黑子了
投递华为等公司10个岗位 > 华为求职进展汇总
点赞 评论 收藏
分享
嵌入式求职之路:可以看我经验😂,https://www.nowcoder.com/share/jump/73221730841876945
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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