2024.3.11 C++作业

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

cpp 复制代码
#include <iostream>

using namespace std;

int main()
{

    char str[20];
    cout << "please enter the str:";
    gets(str);

    int uppcaseCount = 0; //定义大写字母的个数
    int lowcaseCount = 0; //定义小写字母的个数
    int digitCount = 0;   //定义数字的个数
    int spaceCount = 0;   //定义空格的个数
    int otherCount = 0;    //定义其他字符的个数

    for(int i=0; str[i]!='\0';i++)
    {
        if(str[i]>=65 && str[i]<=90)
        {
            uppcaseCount++;
        }
        else if(str[i]>=97 && str[i]<=122)
        {
            lowcaseCount++;
        }
        else if(str[i]>='1' && str[i]<='9')
        {
            digitCount++;
        }
        else if(str[i] == ' ')
        {
            spaceCount++;
        }
        else
        {
            otherCount++;
        }
    }
    cout << "Uppercase letter:" << uppcaseCount << endl;
    cout << "Lowercase letter:" << lowcaseCount << endl;
    cout << "Digits:" << digitCount << endl;
    cout << "Space:" << spaceCount << endl;
    cout << "Ohter characters" << otherCount << endl;


    return 0;
}

2、思维导图

相关推荐
河藕Hou1 天前
Linux - 磁盘/逻辑卷的分区&格式化&挂载
linux
数字化顾问1 天前
C++分布式语音识别服务实践——架构设计与关键技术
c++
智能化咨询1 天前
C++分布式语音识别服务实践——性能优化与实战部署
c++
半桔1 天前
【网络编程】网络通信基石:从局域网到跨网段通信原理探秘
linux·运维·网络协议·php
叫我詹躲躲1 天前
Linux 服务器磁盘满了?教你快速找到大文件,安全删掉不踩坑!
linux·前端·curl
叫我詹躲躲1 天前
3 分钟搞定 Linux 磁盘清理:实用命令 + 自动脚本,新手也会
linux·curl
ajassi20001 天前
开源 C++ QT QML 开发(十四)进程用途
c++·qt·开源
Garc1 天前
Zookeeper删除提供者服务中的指定IP节点
linux·运维·服务器
闻缺陷则喜何志丹1 天前
【C++贪心】P8769 [蓝桥杯 2021 国 C] 巧克力|普及+
c++·算法·蓝桥杯·洛谷
过往入尘土1 天前
Linux:虚拟世界的大门
linux·人工智能