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;
}
相关推荐
汉克老师21 小时前
GESP2025年3月认证C++五级( 第二部分判断题(1-10))
c++·算法·分治算法·线性筛法·gesp5级·gesp五级
橙子也要努力变强21 小时前
volatile与信号
linux·服务器·c++
Shadow(⊙o⊙)1 天前
智能指针、循环引用、锁、删除器
开发语言·c++·后端·visual studio
水云桐程序员1 天前
C++官方文档获取平台
c++·学习方法
Sylvia-girl1 天前
C++模板【上】
开发语言·c++
王老师青少年编程1 天前
csp信奥赛C++高频考点专项训练之贪心算法 --【哈夫曼贪心】:荷马史诗
c++·算法·贪心·csp·信奥赛·哈夫曼贪心·荷马史诗
样例过了就是过了1 天前
LeetCode热题100 最小路径和
c++·算法·leetcode·动态规划
迷途之人不知返1 天前
Stack & Queue
c++·算法
(Charon)1 天前
【C++/Qt】Qt 实现 MQTT 测试工具:连接 Broker、订阅主题与发布消息
开发语言·c++·qt
春蕾夏荷_7282977251 天前
1、c++ acl udp服务器客户端简单实例-服务器端(1)
服务器·c++·udp