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;
}

思维导图

相关推荐
wxin_VXbishe1 小时前
springboot新能源车充电站管理系统小程序-计算机毕业设计源码29213
java·c++·spring boot·python·spring·django·php
05候补工程师2 小时前
【408 从零到一】线性表逻辑特征、存储结构对比与 C/C++ 动态内存分配避坑指南
c语言·开发语言·数据结构·c++·考研
怕什么真理无穷3 小时前
C++面试5_ TCP 粘包2(工业级)
开发语言·c++·tcp/ip
努力努力再努力wz3 小时前
【MySQL 进阶系列】拒绝滥用root:从 mysql.user 到权限校验,带你彻底理解用户管理与授权机制!
android·c语言·开发语言·数据结构·数据库·c++·mysql
雪度娃娃3 小时前
基于TCP的网络词典
网络·c++·tcp/ip·c#
春蕾夏荷_7282977254 小时前
2、c++ acl tcp服务器客户端简单实例-服务器端(1)
服务器·c++·tcp/ip
墨染千千秋4 小时前
C++if判断的使用全解
c++
雪度娃娃4 小时前
设计模式——单例模式
开发语言·c++·设计模式
Lenyiin4 小时前
《LeetCode 顺序刷题》61 - 70
java·c++·python·算法·leetcode·lenyiin
想唱rap4 小时前
应用层HTTPS协议
服务器·网络·c++·网络协议·http·https