題目描述:
輸入一行字符,分別統計出其中英文字母、空格、數字和其它字符的個數。
樣例輸入:
a 1,
樣例輸出:
1
1
1
1
參考代碼:
#include<stdio.h>
#include<string.h>
int main()
{
int letter=0,space=0,number=0,other=0;
int i;
char s[100];
gets(s);
for(i=0;i<strlen(s);i++)
{
if(s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z')
letter++;
else if(s[i]==' ')
space++;
else if(s[i]<='9'&&s[i]>='0')
number++;
else
other++;
}
printf("%d\n%d\n%d\n%d\n",letter,space,number,other);
}