当前位置: 首页 > article >正文

坐牢第三十天(c++)

1.作业:

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

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
    string str;
    cout << "请输入一个字符串:"; 
    getline(cin,str);
    int len = str.length();//字符串实际长度
    cout << "字符串的长度为:";
    cout << len << endl;
    int alphabet=0;//字母个数
    int number=0;//数字个数
    int space=0;//空格个数
    int other=0;//其他字符个数
    for (int  i = 0; i < len; i++)
    {
        if (str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')
        alphabet++;
        else if(str[i]>='0'&&str[i]<='9')
        number++;
        else if(str[i]==' ')
        space++;
        else
        other++;
    }
    cout << "字母有:"<< alphabet <<endl;
    cout << "数字有:"<< number <<endl;
    cout << "空格有:"<< space <<endl;
    cout << "其他字符有:"<< other <<endl;
    return 0;
}

效果图:

 

2.思维导图:


http://www.kler.cn/news/284014.html

相关文章:

  • 【微信小程序】分包--独立分包
  • 请问基于规则和强化学习的各自的优缺点有哪些?应用场景有哪些?今天的北京机器人展上的技术专家的技术
  • 学习日志30
  • 鸿蒙( Beta5.0版)开发实战:自定义TabBar页签
  • 新加坡服务器解决访问慢的方法有哪些?
  • LSTM唐诗生成
  • SX_Git Graph图形化案例详解_20
  • 网易校招面试题 - 如何给 10 台机器安装 Nginx
  • 设备智能语音交互控制,乐鑫ESP32-S3智能AI方案,助力产品个性化交互
  • 计算机毕业设计选题推荐-在线培训平台-Java/Python项目实战
  • 浅析事件驱动Reactor
  • Pyqt5高级技巧:多线程任务、窗体交互、常用控件介绍(含基础Demo)
  • Apache Tomcat与反向代理
  • Elastic Stack(三):Logstash介绍及安装
  • JDBC中的execute, executeQuery, 和 executeUpdate方法区别
  • 如何构建小学至大学素质评价档案系统 —— php Vue 实践指南
  • 【 html+css 绚丽Loading 】 000027 旋风破云扇
  • HTML5 数据 URL(data URL)是什么?
  • Android中AsyncTask的基本用法
  • 如何处理时间序列异常值?理解、检测和替换时间序列中的异常值
  • 智能合约漏洞(四)
  • 美国洛杉矶多ip服务器特点
  • dp+差分数组
  • 8.29笔记
  • 组合式API-reactive和ref函数,computed计算属性,watch函数
  • NASA数据集:ASO L4雷达雪神数据集
  • BSV区块链发布Golang软件开发工具包
  • 开源网络安全大模型 - SecGPT
  • tcp/udp 可视化 调试工具; tcp/udp 发送客户端;查看tcp连接;netassist;packet sender;tcp view;
  • 【JavaEE初阶】HTTP响应报文