提示并输入字符串,统计该字符中大写,小写字母个数,数字个数,空格个数以及其他字符个数
C++完成
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int xiaoxie=0;
int daxie=0;
int num=0;
int kongge=0;
int qita=0;
string str;
getline(cin,str);
for(int i=0;i<str.size();i++)
{
if('a'<=str[i] && 'z'>=str[i])
{
xiaoxie++;
}
else if('A'<=str[i]&&'Z'>=str[i])
{
daxie++;
}
else if(str[i]==' ')
{
kongge++;
}
else if(str[i]>'0'&&str[i]<'9')
{
num++;
}
else
{
qita++;
}
}
cout << "小写个数:" << xiaoxie << endl;
cout << "大写个数: " << daxie << endl;
cout << "空格个数: " << kongge << endl;
cout << "数字个数: " << num << endl;
cout << "其他字符个数: " << qita << endl;
return 0;
}