#include<iostream>
#include<string>

using namespace std;

int main() {
    string s;
    getline(cin, s); // 读取一行字符串

    int uppercase = 0; // 大写字母个数
    int lowercase = 0; // 小写字母个数
    int digit = 0; // 数字个数
    int space = 0; // 空格个数

    for (int i = 0; i < s.length(); i++) {
        if (isupper(s[i])) { // 判断是否大写字母
            uppercase++;
        }
        else if (islower(s[i])) { // 判断是否小写字母
            lowercase++;
        }
        else if (isdigit(s[i])) { // 判断是否数字
            digit++;
        }
        else if (isspace(s[i])) { // 判断是否空格
            space++;
        }
    }

    cout << uppercase << " " << lowercase << " " << digit << " " << space << endl;

    return 0;
}
描述输入一行字符串字符串长度小于10000由大小写字母、阿拉伯数字和空格组成分别统计出其中大写英文字母小写英文字母、阿拉伯数字和空格的个数。输入描述一行字符串字符串长度小于10000由大小写字母、阿拉伯数字和空格组成输出描述分别输出大写英文字母小写英文字母、阿拉伯数字和空格的个数用空格隔开希望能用c++编写代码输入:h0u84nfx 7输出:0 5 4 1

原文地址: http://www.cveoy.top/t/topic/jauU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录