王杰C++day1

#include 

using namespace std;

int main()
{
    cout << "输入一个字符串:" << endl;
    string str;
    int a = 0,b = 0,c = 0,d = 0,e = 0;
    getline(cin,str);
    for(int i = 0;i < (int)str.size();i++)
    {
        if(str[i] >= 'A' && str[i] <= 'Z' )
            a+=1;
        else if(str[i] >= 'a' && str[i] <= 'z' )
            b+=1;
        else if(str[i] >= '0' && str[i] <= '9' )
            c+=1;
        else if(str[i] == ' ')
            d+=1;
        else
            e+=1;
    }
    cout << "大写字母个数:" << a << endl;
    cout << "小写字母个数:" << b << endl;
    cout << "数字个数:" << c << endl;
    cout << "空格个数:" << d << endl;
    cout << "其他字符个数:" << e << endl;
    return 0;
}

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