1009: C基础-统计字符
-
题目描述:
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
-
样例输入
a 1,
-
样例输出
1
1
1
1
#include <iostream>
#include "stdio.h"
using namespace std;
int main()
{
char s;
int i=0,j=0,k=0,m=0;
while((s=getchar())!='\n')
{
if((s<='z'&&s>='a')||(s<'Z'&&s>'A'))i++;
else if(s==' ') j++;
else if(s<58&&s>47)k++;
else m++;
}
cout<<i<<endl;
cout<<j<<endl;
cout<<k<<endl;
cout<<m<<endl;
return 0;
}