8.5作业

1.思维导图

2.提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数,要求使用C++风格字符串完成

cpp 复制代码
#include <iostream>

using namespace std;

int main()
{
    string str;
    cout << "请输入一个字符串" << endl;
    getline(cin,str);
    int big = 0, small = 0, num = 0, space = 0,other = 0, size = str.size();
    for(int i=0;i<size;i++)
    {
        if(str[i]>='A' && str[i]<='Z')
            big++;
        else if(str[i]>='a' && str[i]<='z')
            small++;
        else if(str[i]>=0 && str[i]<=9)
            num++;
        else if(str[i] == ' ')
            space++;
        else
            other++;
    }
    cout << "大写字母个数:" << big << endl;
    cout << "小写字母个数:" << small << endl;
    cout << "数字个数:" << num << endl;
    cout << "空格个数:" << space << endl;
    cout << "其他字符个数:" << other << endl;
    return 0;
}
相关推荐
m0_748233171 小时前
30秒掌握C++核心精髓
开发语言·c++
风清扬_jd2 小时前
libtorrent-rasterbar-2.0.11编译说明
c++·windows·p2p
u0109272712 小时前
C++中的RAII技术深入
开发语言·c++·算法
彷徨而立2 小时前
【C/C++】strerror、GetLastError 和 errno 的含义和区别?
c语言·c++
誰能久伴不乏2 小时前
【Qt实战】工业级多线程串口通信:从底层协议设计到完美收发闭环
linux·c++·qt
2401_832131952 小时前
模板错误消息优化
开发语言·c++·算法
金枪不摆鳍2 小时前
算法--二叉搜索树
数据结构·c++·算法
liu****3 小时前
4.Qt窗口开发全解析:菜单栏、工具栏、状态栏及对话框实战
数据库·c++·qt·系统架构
近津薪荼3 小时前
优选算法——双指针6(单调性)
c++·学习·算法
helloworldandy3 小时前
高性能图像处理库
开发语言·c++·算法