C++day1

一、思维导图

二、提示并输入一个字符串,统计该字符串中字母个数、数字个数、空格个数、其他字符的个数

cpp 复制代码
#include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int letter = 0;
        int number =0;
        int space = 0;
        int other = 0;

        string str;
        cout << "请输入字符串:";
        getchar();
        getline(cin,str);
        for(int i=0;i<str.length();i++)
        {
            char c = str[i];
            //字母
            if((c >= 'A' && c <= 'Z') ||(c >= 'a' && c <= 'z'))
            {
                letter++;
            }
            //数字
            else if(c >= '0' && c <='9')
            {
                number++;
            }
            //空格
            else if(c == ' ')
            {
                space++;
            }
            else
                other++;
        }
        cout<<"字母:"<<letter<<endl<<"数字:"<<number<<endl<<"空格:"<<space<<endl<<"其它:"<<other<<endl;
    }

    return 0;
}
相关推荐
adam_life4 分钟前
http://noi.openjudge.cn/——2.5基本算法之搜索——200:Solitaire
算法·宽搜·布局唯一码
超爱笑嘻嘻26 分钟前
shared_ptr八股收集 C++
c++
我想进大厂1 小时前
图论---朴素Prim(稠密图)
数据结构·c++·算法·图论
我想进大厂1 小时前
图论---Bellman-Ford算法
数据结构·c++·算法·图论
AIGC大时代1 小时前
高效使用DeepSeek对“情境+ 对象 +问题“型课题进行开题!
数据库·人工智能·算法·aigc·智能写作·deepseek
光而不耀@lgy1 小时前
C++初登门槛
linux·开发语言·网络·c++·后端
啊丢_1 小时前
C++——Lambda表达式
开发语言·c++
CODE_RabbitV1 小时前
【深度强化学习 DRL 快速实践】近端策略优化 (PPO)
算法
Wendy_robot2 小时前
【滑动窗口+哈希表/数组记录】Leetcode 438. 找到字符串中所有字母异位词
c++·算法·leetcode
程序员-King.2 小时前
day49—双指针+贪心—验证回文串(LeetCode-680)
算法·leetcode·贪心算法·双指针