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;
}
相关推荐
Lazionr6 分钟前
unordered_map和unordered_set的使用
开发语言·c++·算法
进化中的刀盾兽21 分钟前
从零实现 C++ Json-Rpc(九):从 TCP 字节流中拆出完整消息——MuduoBuffer 与 LVProtocol
c++·rpc
HZY1618yzh1 小时前
下一代编程语言出炉
c++·算法
wyhwust1 小时前
No1-绪论
c++
无名猿1 小时前
C++ 对象内存模型:vtable 布局、多继承 vptr、RTTI 与 dynamic_cast 走查
c++·内存管理·调试技巧·现代c++
All for pursuit.1 小时前
【动态规划-8】152.乘积最大子数组
数据结构·c++·算法·leetcode·动态规划
INGNIGHT2 小时前
1861 · 老鼠跳跃(坐标型dp)
数据结构·c++
Lazionr2 小时前
手撕 unordered_set 和 unordered_map,剖析哈希表底层实现
c++·算法
xie0510_2 小时前
Any类简要实现
开发语言·c++·算法
道尔柯南2 小时前
C++ 入门基础详解:从第一个程序到核心语法特性
开发语言·c++