题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5?tpId=37&tqId=21263&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=

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

int main() {
    string str;
    int a =0,b =0,c =0,d =0;
    getline(cin,str);
    for(int i =0;i <str.length();i++){
        if(isalpha(str[i])){
            a++;
        }
        if(isspace(str[i])){
            b++;
        }
        if(isdigit(str[i])){
            c++;
        }
        if(ispunct(str[i])){
            d++;
        }
    }
    cout << a <<endl;
    cout << b <<endl;
    cout << c <<endl;
    cout << d <<endl;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 20:37
点赞 评论 收藏
分享
04-19 10:50
门头沟学院 Java
想奋斗的小山竹在改简...:学院本能过简历筛选吗,我怎么看一些一本都过不了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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