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;
}
相关推荐
im_AMBER6 小时前
Leetcode 74 K 和数对的最大数目
数据结构·笔记·学习·算法·leetcode
t198751286 小时前
电力系统经典节点系统潮流计算MATLAB实现
人工智能·算法·matlab
断剑zou天涯6 小时前
【算法笔记】蓄水池算法
笔记·算法
长安er7 小时前
LeetCode 206/92/25 链表翻转问题-“盒子-标签-纸条模型”
java·数据结构·算法·leetcode·链表·链表翻转
唯道行7 小时前
计算机图形学·23 Weiler-Athenton多边形裁剪算法
算法·计算机视觉·几何学·计算机图形学·opengl
CoderYanger7 小时前
动态规划算法-01背包问题:50.分割等和子集
java·算法·leetcode·动态规划·1024程序员节
花月C7 小时前
个性化推荐:基于用户的协同过滤算法
开发语言·后端·算法·近邻算法
咕咕嘎嘎10247 小时前
C++六个默认成员函数
c++
lxh01137 小时前
最长递增子序列
前端·数据结构·算法
Youyzq8 小时前
前端项目发布到cdn上css被编译失效问题rgba失效和rgb失效
前端·css·算法·cdn