C++初学

1>思维导图

2>试编程

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

cpp 复制代码
#include <iostream>
#include<string.h>
using namespace std;

int main()
{
    string str;
    cout << "please enter str:";
    getline(cin,str);
    int len = str.size();
    int cap = 0;//大写字母
    int low = 0;//小写字母
    int spa = 0;//空格
    int num = 0;//数字
    int oth = 0;//其他
    for(int i=0;i<len;i++)
    {
        if(str[i] >= 'a' && str[i] <= 'z')
        {
            low++;
        }
        else if(str[i] >= 'A' && str[i] <= 'Z')
        {
            cap++;
        }
        else if(str[i] >= '0' && str[i] <= '9')
        {
            num++;
        }
        else if(str[i] == ' ')
        {
            spa++;
        }
        else
        {
            oth++;
        }
    }
    cout << "cap=" << cap << endl;
    cout << "low=" << low << endl;
    cout << "num=" << num << endl;
    cout << "oth=" << oth << endl;
    cout << "spa=" << spa << endl;

    return 0;
}

运行结果:

相关推荐
caimouse6 分钟前
ReactOS 窗口系统分析(14):计时器/属性/加速键/热键 — timer.c + prop.c + accelerator.c + hotkey.c
c语言·开发语言·reactos
circuitsosk13 分钟前
Python 模块与包管理:import 机制、虚拟环境与 pip 完全指南
开发语言·python·pip·依赖管理·模块与包
就叫飞六吧13 分钟前
两道门:X-Frame-Options 和 SameSite 到底谁管什么
开发语言·chrome·ai编程
水饺编程14 分钟前
第5章,[Win32 章节] :贝塞尔样条曲线(一)
c语言·c++·windows·visual studio
fl17683128 分钟前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf
weixin_4407305032 分钟前
python+request实现接口-小结
开发语言·python
ZJU_统一阿萨姆1 小时前
【算子开发】扫描(Scan)与前缀和
开发语言·arm开发·架构·系统架构·硬件架构
-凌凌漆-1 小时前
【C语言】结构体typedef struct与struct的区别
c语言·开发语言
程序员打怪兽1 小时前
C++:类与对象,封装,继承,多态,构造/析构,重载/重写
c++
Escalating_xu1 小时前
【C++ STL简介】从六大组件到容器、迭代器与算法协作
java·c++·算法