2023年11月28日作业

#include 

using namespace std;

int main()
{
    cout << "请输入一个字符串:" << endl;
    string str;
    int num=0,ch=0,CH=0,kg=0,oth=0;
    getline(cin,str);
    int len = str.size();
    for(int i=0; i='A' && str[i] <= 'Z' )
        {
            CH++;
        }
        else if(str[i] >= 'a' && str[i] <= 'z')
        {
            ch++;
        }
        else if(str[i] >= '0' && str[i] <= '9')
        {
            num++;
        }
        else if(str[i] == ' ')
        {
            kg++;
        }
        else
        {
            oth++;
        }
    }
    cout << "大写字符个数为:" << CH << endl;
    cout << "小写字符个数为:" << ch << endl;
    cout << "数字个数为:" << num << endl;
    cout << "空格个数为:" << kg << endl;
    cout << "其他字符个数为:" << oth << endl;
    return 0;
}

思维导图

2023年11月28日作业_第1张图片

你可能感兴趣的:(c++)