题目描述
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
输入
一行字符
输出
统计值
样例输入
aklsjflj123 sadf918u324 asdf91u32oasdf/.’;123
样例输出
23 16 2 4
#include<iostream>
using namespace std;
int main()
{
char ch;
int count_letter = 0;
int count_number = 0;
int count_space = 0;
int count_other = 0;
cin.get(ch);
while (ch != '\n'){
if ((ch >= 'a'&&ch <= 'z') || (ch >= 'A'&&ch <= 'Z')) count_letter++;
else if (ch >= '0' && ch <= '9') count_number++;
else if (ch == ' ')count_space++;
else count_other++;
cin.get(ch);
}
cout << count_letter << " " << count_number << " " << count_space << " " << count_other;
return 0;
}