?
#include <iostream>
using namespace std;
int main()
{
cout << "please enter str" << endl;
string str;
getline(cin,str);
int count[5]={0,0,0,0,0};
int num = str.size();
for(int i=0;i<num;i++)
{
if('a' <= str[i] && str[i] <= 'z')
{
count[0]++;
}
else if('A' <= str[i] && str[i] <='Z')
{
count[1]++;
}
else if('0' <= str[i] && str[i] <= '9')
{
count[2]++;
}
else if (' ' == str[i])
{
count[3]++;
}
else
{
count[4]++;
}
}
cout << "小写字母=" << count[0] << endl;
cout << "大写字母=" << count[1] << endl;
cout << "数字个数=" << count[2] << endl;
cout << "空格数=" << count[3] << endl;
cout << "其他字符数=" << count[4] << endl;
return 0;
}
?
?