1> 提示并输入一个字符串,统计该字符串中字母个数、数字个数、空格个数、其他字符的个数
#include <iostream>using namespace std;int main()
{string s;cout << "请输入字符串>>>";getline(cin,s);int letter=0,digit=0,blank=0,other=0;for(char ch : s){if((ch<='z'&& ch>='a')||(ch<='Z'&& ch>='A')){letter++;}else if(ch<='9'&& ch>='0'){digit++;}else if(ch==' '){blank++;}else{other++;}}cout <<"字母有"<<letter<<"个 数字有"<<digit<<"个 空格有"<<blank<<" 其他字符有"<<other<<"个"<<endl;return 0;
}