如何用凡科网建立一个网站,wordpress网站二次开发,北京王府井附近的酒店,微博付费推广有用吗提示并输入一个字符串#xff0c;统计该字符串中字母、数字、空格、其他字符的个数并输出
代码展示
#include iostreamusing namespace std;int main() {string str;int countc 0; // 字母计数int countn 0; // 数字计数int count 0; // 空格计数int counto 0;…提示并输入一个字符串统计该字符串中字母、数字、空格、其他字符的个数并输出
代码展示
#include iostreamusing namespace std;int main() {string str;int countc 0; // 字母计数int countn 0; // 数字计数int count 0; // 空格计数int counto 0; // 其他字符计数cout 请输出一个字符串: endl;getline(cin, str);int len str.size();for (int i 0; i len; i) {if ((str[i] A str[i] Z) || (str[i] a str[i] z)) {countc;} else if (str[i] 0 str[i] 9) { countn;} else if (str[i] ) {count;} else {counto;}}cout 字母 countc endl;cout 数字 countn endl;cout 空格 count endl;cout 其他字符 counto endl;return 0;
}运行结果 思维导图