输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。
#include<iostream>
#include<string>
using namespace std;
int main()
{
string line;
while(getline(cin,line))
{
int alpha = 0, space = 0, digit = 0,other = 0;
for(auto i:line)
if(isalpha(i))
alpha++;
else if (isdigit(i))
digit++;
else if(i==' ')
space++;
else
other++;
cout<<alpha<<endl<<space<<endl<<digit<<endl<<other<<endl;
}
return 0;
}