题目描述
输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。
#include<iostream>
using namespace std;
int main(){
string s;
while(getline(cin,s)){
int num_letter=0,num_block=0,num_num=0,num_other=0;
for(auto i:s){
if(i>='a'&&i<='z')
num_letter++;
else if(i==' ')
num_block++;
else if(i>='0'&&i<='9')
num_num++;
else
num_other++;
}
cout<<num_letter<<endl<<num_block<<endl<<num_num<<endl<<num_other<<endl;
}
}
京公网安备 11010502036488号