题目描述:
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
输入:
输出:
样例输入
a 1,
样例输出
1 1 1 1
提交
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char c;
int letter=0,space=0,num=0,other=0;
while((c=getchar())!='\n')
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z')letter++;
else if(c>='0'&&c<='9')num++;
else if(c==' ')space++;
else other++;
}
cout<<letter<<'\n'<<space<<'\n'<<num<<'\n'<<other;
return 0;
}
要点
while((c=getchar())!='\n'),输入下个字符不为回车时。