1> 思维导图
2> 试编程
提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数
#include <iostream>
#include <array>
using namespace std;
int main()
{
cout << "请输入一个字符串:";
//定义存储容器
int capital=0;
int lowercase = 0;
int number = 0;
int blank = 0;
int other = 0;
string buf = "";
getline(cin, buf);
int len;
len = buf.size();
//计算个数
for(int i=0; i<len; i++)
{
if(buf[i] > 'A' && buf[i] < 'Z')
{
capital++;
}
else if(buf[i] > 'a' && buf[i] < 'z')
{
lowercase++;
}
else if(buf[i] > '0' && buf[i] <'9')
{
number++;
}
else if(buf[i] == ' ')
{
blank++;
}
else
{
other++;
}
}
cout << "大写字母:" << capital << endl;
cout << "小写字母:" << lowercase << endl;
cout << "数字个数:" << number << endl;
cout << "空格个数:" << blank << endl;
cout << "其他字符:" << other << endl;
return 0;
}