24.1.24 DAY1 C++

思维导图:

1.

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

代码:

#include <iostream>
#include <array>
using namespace std;

int main()
{
    int big=0;
    int small=0;
    int num=0;
    int space=0;
    int other=0;
    
    //string a="";
    string a;
    cout << "请输入字符串" << endl;
    getline(cin,a);
    
    cout << a <<endl;
    
    int i=a.size();
    cout << i << endl;
    for(i=a.size();i>0;i--)
    {
        if(a[i-1]==' ')
            space++;
        else if(a[i-1]<='9'&&a[i-1]>='0')
            num++;
        else if(a[i-1]<='Z'&&a[i-1]>='A')
            big++;
        else if(a[i-1]<='z'&&a[i-1]>='a')
            small++;
        else
            other++;
    }
    
    cout << "空格数量为"  << space <<endl;
    cout << "数字数量为"  << num <<endl;
    cout << "大写字母数量为"  << big <<endl;
    cout << "小写字母数量为"  << small <<endl;
    cout << "其他字符数量为"  << other <<endl;
    return 0;
}

运行结果:

相关推荐

  1. <span style='color:red;'>240124</span>

    240124

    2024-01-26 01:04:01      33 阅读
  2. <span style='color:red;'>DAY</span><span style='color:red;'>1</span><span style='color:red;'>C</span>++

    DAY1C++

    2024-01-26 01:04:01      34 阅读
  3. <span style='color:red;'>C</span>++ <span style='color:red;'>day</span><span style='color:red;'>1</span>

    C++ day1

    2024-01-26 01:04:01      34 阅读
  4. <span style='color:red;'>C</span>++ <span style='color:red;'>day</span><span style='color:red;'>1</span>

    C++ day1

    2024-01-26 01:04:01      14 阅读
  5. C++ Primer 学习 -- Day 1

    2024-01-26 01:04:01       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-26 01:04:01       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-26 01:04:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-26 01:04:01       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-26 01:04:01       20 阅读

热门阅读

  1. Vue3组件通信相关内容整理

    2024-01-26 01:04:01       39 阅读
  2. 5G_射频测试_接收机测量(五)

    2024-01-26 01:04:01       27 阅读
  3. Leetcode724.寻找数组的中心索引

    2024-01-26 01:04:01       34 阅读
  4. Typescript的一些总结和部分代码

    2024-01-26 01:04:01       36 阅读
  5. 26.删除排序数组中的重复项(力扣LeetCode)

    2024-01-26 01:04:01       33 阅读
  6. AndroidStudio 无法打开 arb 文件

    2024-01-26 01:04:01       38 阅读
  7. leetcode2765. 最长交替子数组

    2024-01-26 01:04:01       33 阅读
  8. DockerCompose

    2024-01-26 01:04:01       41 阅读
  9. 优橙内推专场—远程交付篇

    2024-01-26 01:04:01       36 阅读
  10. 常见域控开放端口及其作用

    2024-01-26 01:04:01       30 阅读