1>思维导图
2>试编程
提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数要求使用C++风格字符串完成
#include <iostream>
#include<string.h>
using namespace std;int main()
{string str;cout << "please enter str:";getline(cin,str);int len = str.size();int cap = 0;//大写字母int low = 0;//小写字母int spa = 0;//空格int num = 0;//数字int oth = 0;//其他for(int i=0;i<len;i++){if(str[i] >= 'a' && str[i] <= 'z'){low++;}else if(str[i] >= 'A' && str[i] <= 'Z'){cap++;}else if(str[i] >= '0' && str[i] <= '9'){num++;}else if(str[i] == ' '){spa++;}else{oth++;}}cout << "cap=" << cap << endl;cout << "low=" << low << endl;cout << "num=" << num << endl;cout << "oth=" << oth << endl;cout << "spa=" << spa << endl;return 0;
}
运行结果: