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

运行结果:

流程图:

相关推荐
NAGNIP4 小时前
轻松搞懂全连接神经网络结构!
人工智能·算法·面试
NAGNIP4 小时前
一文搞懂激活函数!
算法·面试
董董灿是个攻城狮4 小时前
AI 视觉连载7:传统 CV 之高斯滤波实战
算法
爱理财的程序媛10 小时前
openclaw 盯盘实践
算法
端平入洛11 小时前
auto有时不auto
c++
MobotStone13 小时前
Google发布Nano Banana 2:更快更便宜,图片生成能力全面升级
算法
颜酱17 小时前
队列练习系列:从基础到进阶的完整实现
javascript·后端·算法
用户57573033462417 小时前
两数之和:从 JSON 对象到 Map,大厂面试官到底在考察什么?
算法
程序猿追17 小时前
“马”上行动:手把手教你基于灵珠平台打造春节“全能数字管家”
算法