题解 | #统计字符#

统计字符

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

#include <iostream>
using namespace std;

int main() {
    int en = 0;
    int spa = 0;
    int num = 0;
    int other = 0;
    string str;
    getline(cin,str);
    cin>>str;
    for(int i = 0;i<str.size();i++){
        if(str[i]>='a'&&str[i]<='z'){
            en++;
        }else if(str[i]>='A'&&str[i]<='Z'){
            en++;
        }else if(str[i]>='0'&&str[i]<='9'){
            num++;
        }else if(str[i] == ' '){
            spa++;
        }else{
            other++;
        }
    }
    cout<<en<<endl;
    cout<<spa<<endl;
    cout<<num<<endl;
    cout<<other<<endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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