思维导图
提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数
要求使用C++风格字符串完成
#include <iostream> #include <iomanip> using namespace std; int main() {string a;cout<<"输入一个字符串"<<endl;getline(cin,a);int size=a.size();int huge=0,little=0,space=0,passwd=0,other=0;for(int i=0;i<size;i++){if(a.at(i)>='A'&&a.at(i)<='Z')huge++;else if(a.at(i)>='a'&&a.at(i)<='z')little++;else if(a.at(i)>='0'&&a.at(i)<='9')passwd++;else if(a.at(i)==' ')space++;elseother++;}cout<<"大写个数为:"<<huge<<endl;cout<<"小写个数为:"<<little<<endl;cout<<"数字个数为:"<<passwd<<endl;cout<<"空格个数为:"<<space<<endl;cout<<"其他符号个数为:"<<other<<endl;return 0; }