day1_C++:实现C++风格字符串输出

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

程序代码:

cpp 复制代码
#include <iostream>//标准输入输出流
#include <string.h>//C中字符串相关头文件
using namespace std;

int main()
{
    char str[100];
    int big = 0, small = 0, num = 0, space = 0, other = 0;

    cout << "请输入一个字符串:";
    cin.getline(str, 100);//从标准输入输出流读取字符
    for (int i = 0; str[i] != '\0'; 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;
    }

运行结果:

流程图:

相关推荐
南 阳20 分钟前
Python从入门到精通day66
开发语言·python
刀法如飞41 分钟前
Go 字符串查找的 20 种实现方式,用不同思路解决问题
算法·面试·程序员
十八旬1 小时前
快速安装ClaudeCode完整指南
开发语言·windows·python·claude
前进的李工2 小时前
EXPLAIN输出格式全解析:JSON、TREE与可视化
开发语言·数据库·mysql·性能优化·explain
Byron Loong2 小时前
【c++】为什么有了dll和.h,还需要包含lib
java·开发语言·c++
Dlrb12112 小时前
C语言-指针数组与数组指针
c语言·数据结构·算法·指针·数组指针·指针数组·二级指针
WL_Aurora2 小时前
Python 算法基础篇之集合
python·算法
独隅2 小时前
CodeX + Visual Studio Code 联动的全面指南
开发语言·php
坚果派·白晓明2 小时前
【鸿蒙PC三方库移植适配框架解读系列】第一篇:Lycium C/C++ 三方库适配 — 概述与环境配置
c语言·开发语言·c++·harmonyos·开源鸿蒙·三方库·c/c++三方库
平行侠3 小时前
A15 工业路由器IP前缀高速检索与内存压缩系统
网络·tcp/ip·算法