1.提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数
#include <iostream>using namespace std;int main()
{string buf;cout << "输入字符串" << endl;getline(cin,buf);int capital = 0,lower = 0,numble = 0,blank = 0,character = 0;int i = 0;int size=buf.size();cout << size << endl;for(i=0;i<size;i++){if(buf.at(i) >= 'A' && buf.at(i) <= 'Z'){capital++;}else if(buf.at(i) >= 'a' && buf.at(i) <= 'z'){lower++;}else if(buf.at(i) >= '0' && buf.at(i) <= '9'){numble++;}else if(buf.at(i) == ' '){blank++;}else{character++;}}cout << "大写字母 = " << capital << endl;cout << "小写字母 = " << lower << endl;cout << "数字 = " << numble << endl;cout << "空格 = " << blank << endl;cout << "其余字符 = " << character << endl;return 0;
}
2.思维导图