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、思维导图

相关推荐
iCxhust17 分钟前
一个用于在 Ubuntu 22.04.3 LTS 上显示文件系统超级块信息的 C 程序
linux·c语言·ubuntu
小指纹18 分钟前
巧用Bitset!优化dp
数据结构·c++·算法·代理模式·dp·bitset
liulilittle38 分钟前
游戏加速器核心技术:动态超发
开发语言·网络·c++·网络协议·游戏·加速器·游戏加速
Bella的成长园地38 分钟前
linux 系统依赖包查询命令汇总
linux·运维·服务器
Arthurmoo1 小时前
Linux系统集群部署模块之Keepalived双机热备
linux·git·github
hweiyu001 小时前
Linux 命令:uname
linux·运维·服务器
大时代11052 小时前
Linux 基础 IO
linux
RIVOTEK_OPENVELA2 小时前
OpenVela之 Arch Timer 驱动框架使用指南
linux·开源软件·iot
longerxin20202 小时前
在 CentOS 8 上彻底卸载 Kubernetes(k8s)
linux·kubernetes·centos
阿竹.3 小时前
Linux运维新手的修炼手扎之第19天
linux·运维·服务器