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

运行结果:

流程图:

相关推荐
saltymilk25 分钟前
C++ 模板参数推导问题小记(模板类的模板构造函数)
c++·模板元编程
感哥43 分钟前
C++ lambda 匿名函数
c++
沐怡旸7 小时前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥7 小时前
C++ 内存管理
c++
聚客AI7 小时前
🙋‍♀️Transformer训练与推理全流程:从输入处理到输出生成
人工智能·算法·llm
大怪v10 小时前
前端:人工智能?我也会啊!来个花活,😎😎😎“自动驾驶”整起!
前端·javascript·算法
惯导马工12 小时前
【论文导读】ORB-SLAM3:An Accurate Open-Source Library for Visual, Visual-Inertial and
深度学习·算法
骑自行车的码农13 小时前
【React用到的一些算法】游标和栈
算法·react.js
博笙困了14 小时前
AcWing学习——双指针算法
c++·算法
感哥14 小时前
C++ 指针和引用
c++