| 题目描述 |
| 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 |
| 输入 |
| 无 |
| 输出 |
| 无 |
| 样例输入 |
a 1, |
| 样例输出 |
1
1
1
1 |
#include <stdio.h>
#include<string.h>int main() {char str[128]; //定义字符串int alphabet=0,space=0,number=0,other=0;gets(str); //字符串的输入int i=0;for(int i=0;i<strlen(str);i++){ //strlen()求字符串的长度if((str[i]>='a' && str[i]<='z') ||(str[i])>='A' && str[i]<='Z'){alphabet++;}else if(str[i]==' '){space++;} else if(str[i]>='0' && str[i]<='9'){ //因为是char型所以加''number++;}else{other++;}}printf("%d\n",alphabet);printf("%d\n",space);printf("%d\n",number);printf("%d",other);return 0;
}