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;
}
相关推荐
wunaiqiezixin8 小时前
如何在C++中创建和管理线程
c++
雪度娃娃9 小时前
转向现代C++——在意为改写的函数添加 override
开发语言·c++
王老师青少年编程9 小时前
csp信奥赛C++高频考点专项训练之前缀和&差分 --【一维差分】:[NOIP 2018 提高组] 铺设道路
c++·前缀和·差分·csp·高频考点·信奥赛·铺设道路
星马梦缘9 小时前
aaaaa
数据结构·c++·算法
喵星人工作室10 小时前
C++火影忍者1.1.2
开发语言·c++
basketball61610 小时前
C++ 中的 ptrdiff_t 详解
开发语言·c++
wunaiqiezixin10 小时前
互斥锁与自旋锁的区别
c++
代码中介商11 小时前
深入解析STL中的stack、queue与priority_queue
开发语言·c++
磊 子12 小时前
STL无序关联容器—unorded_set+unorded_map
开发语言·c++
初夏睡觉12 小时前
数据结构学习之~二叉堆 (P3378 【模版】堆)
数据结构·c++·学习