c++day1

提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数

要求使用C++风格字符串完成

cpp 复制代码
#include <iostream>

using namespace std;

int main()
{
    string str;
    cout << "请输入一个含有大小写字母,空格,特殊字符的字符串:" << endl;
    getline(cin,str);//getline可以输入含有带空格的字符串
    int size=str.size();
    int big=0,small=0,a=0,k=0,s=0;
    for (int i=0;i<size;i++)
    {
        if (str.at(i)>='A' && str.at(i)<='Z')
        {
            big++;
        }
        else if (str.at(i)>='a' && str.at(i)<='z')
        {
            small++;
        }
        else if (str.at(i)>='0' && str.at(i)<='9')
        {
            a++;
        }
        else if (str.at(i)==' ')
        {
            k++;
        }
        else
        {
            s++;
        }
    }
    cout << "大写字母=" << big << endl;
    cout << "小写字母=" << small << endl;
    cout << "数字=" << a << endl;
    cout << "空格=" << k << endl;
    cout << "特殊字符=" << s<< endl;
    return 0;
}
相关推荐
不想写代码的星星1 天前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
樱木Plus3 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit5 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_6 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星6 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛8 天前
delete又未完全delete
c++
端平入洛9 天前
auto有时不auto
c++
哇哈哈202110 天前
信号量和信号
linux·c++
多恩Stone10 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马10 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost