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;
}
相关推荐
Je1lyfish4 小时前
CMU15-445 (2025 Fall/2026 Spring) Project#3 - QueryExecution
linux·c语言·开发语言·数据结构·数据库·c++·算法
Brilliantwxx5 小时前
【C++】 vector(代码实现+坑点讲解)
开发语言·c++·笔记·算法
叼烟扛炮6 小时前
C++第三讲:类和对象(中)
开发语言·c++·类和对象
KuaCpp6 小时前
C++新特性学习
c++·学习
墨染千千秋6 小时前
C/C++ Keywords
c语言·c++
ximu_polaris6 小时前
设计模式(C++)-行为型模式-中介者模式
c++·设计模式·中介者模式
CSCN新手听安8 小时前
【Qt】Qt窗口(八)QFontDialog字体对话框,QInputDialog输入对话框的使用,小结
开发语言·c++·qt
tumu_C8 小时前
用std::function减缓C++模板代码膨胀和编译压力的一个场景
开发语言·c++
Hical619 小时前
C++17 实战心得:那些真正改变我写代码方式的特性
c++
Hical6110 小时前
实测:C++20 协程 vs Go Gin vs Rust Actix,谁的 Web 性能更强?
c++