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

运行结果:

流程图:

相关推荐
lly2024067 小时前
Bootstrap 警告框
开发语言
2601_949146537 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
你撅嘴真丑8 小时前
第九章-数字三角形
算法
曹牧8 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
在路上看风景8 小时前
19. 成员初始化列表和初始化对象
c++
KYGALYX8 小时前
服务异步通信
开发语言·后端·微服务·ruby
uesowys8 小时前
Apache Spark算法开发指导-One-vs-Rest classifier
人工智能·算法·spark
zmzb01038 小时前
C++课后习题训练记录Day98
开发语言·c++
ValhallaCoder8 小时前
hot100-二叉树I
数据结构·python·算法·二叉树
董董灿是个攻城狮8 小时前
AI 视觉连载1:像素
算法