思维导图![](https://i-blog.csdnimg.cn/direct/83a8f875af8e42ee950c01f0137be33d.png)
作业
提示并输入一个字符串,统计该字符串中字母个数、数字个数、空格个数、其他字符的个数
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string arr={0};
cout << "请输入一个字符串" << endl;
getline(cin,arr);
int len =arr.length();
char brr[128]={0};
strcpy(brr,arr.data());
int zhi_mu=0;
int shu_zi=0;
int kong_ge=0;
int other=0;
for(int i=0;i<len;i++)
{
if((brr[i]>='a'&&brr[i]<='z')||(brr[i]>='A'&&brr[i]<='Z'))
{
zhi_mu++;
}else if(brr[i]==' ')
{
kong_ge++;
}else if(brr[i]>='0'&&brr[i]<='9')
{
shu_zi++;
}else
{
other++;
}
}
cout<<"该字符串中字母有"<<zhi_mu<<"数字有"<<shu_zi<<"空格有"<<kong_ge<<"其他字符有"<<other<<endl;
return 0;
}