统计数字、字母、空格、其他字符练习题

描述

输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。

数据范围:输入的字符串长度满足 1≤n≤1000 1≤n≤1000

输入描述:

输入一行字符串,可以有空格

输出描述:

统计其中英文字符,空格字符,数字字符,其他字符的个数

示例1

输入:

复制代码
1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\\/;p0-=\\][

输出:

复制代码
26
3
10
12
复制代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    getline(cin,str);
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    for(int i=0;i<str.size();i++)
    {
        if(isalpha(str[i]))
        {
            a++;
        }
        else if(str[i]==' ')
        {
            b++;
        }
        //else if(str[i]>=0&&str[i]<=9)//
        else if(str[i]>='0'&&str[i]<='9')
        {
            c++;
        }
        else
        {
            d++;

        }
    }
    cout<<a<<endl;
    cout<<b<<endl;
    cout<<c<<endl;
    cout<<d<<endl;
}
相关推荐
动词ing2 小时前
【题目练习】盛最多水的容器
算法·目标检测
海绵宝宝转agent2 小时前
2026-10-14算法+面经总结
java·笔记·算法·缓存
虚无的纽扣2 小时前
【力扣刷题】第四天:三数之和、四数之和
算法·leetcode·职场和发展
ZiLing2 小时前
2026 ROS 2 Lyrical 工程实例(一):从零搭建 AMR 激光 SLAM——Gazebo、slam_toolbox 与 Nav2 全链路跑通
算法
巴糖2 小时前
为什么你的大模型总在胡说八道?—— top_k /top_p/temperature 调参实战手册
算法
rou2 小时前
LeetCode410.分割数组的最大值
算法
垆边人似月.2 小时前
华为题:字符串中最长连续数字串
开发语言·c++·算法
_不会dp不改名_2 小时前
leetcode_3273 数位平方和的最大值
算法·leetcode·职场和发展
vivo互联网技术2 小时前
SSR-Merge:把 LoRA 合并从"参数算术"变成"信号路由" | ICML 2026
人工智能·算法·计算机视觉
罗湖老棍子2 小时前
座位安排(洛谷-P2071)
c++·算法·图论·匈牙利算法·二分图匹配