2024.3.10 C++

提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数要求使用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;
}

思维导图

相关推荐
念恒1230629 分钟前
网络基础
linux·网络·c++
mct1231 小时前
c++ iconv 字符utf-8转换gb2312失败
开发语言·c++
ziguo11221 小时前
Windows API 文件操作超级指南——从入门到内核
c++·windows·visualstudio
zhangfeng11333 小时前
Ascendc 大语言模型框架 AscendCraft 和pypto 的区别 pypto生成算子c++源码吗
c++·人工智能·语言模型·算子开发
一只小灿灿3 小时前
C++ 修饰符全面详解
开发语言·c++
code_pgf3 小时前
C/C++ 中 `typedef` 关键字详解
c语言·c++
会周易的程序员4 小时前
js-shm: 高性能 Node.js 共享内存模块
开发语言·javascript·c++·node.js·共享内存·shm
2023自学中5 小时前
imx6ull 开发板 贪吃蛇, C++11 SDL2 无硬件GPU优化版
linux·c++
anscos5 小时前
为CUDA 代码引入静态分析
c++·工业软件·功能检测
众少成多积小致巨5 小时前
C++ 规范参考(中)
c++