解题思路:数字字符在‘0’-‘9’之间,英文字符在‘a’-‘z’和‘A’-‘Z’之间,空格为‘ ’
注意事项:在输入字符的时候用gets(),scanf会把空格当作是连个单词的分隔符
参考代码:
#include <stdio.h> #include <string.h> int main() { char str[200]; int english = 0, num = 0, space = 0, other = 0; gets(str); for (int i = 0; i < strlen(str); ++i) { if(str[i]>='0' && str[i]<='9') num++; else if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z')) english++; else if(str[i]==' ') space++; else other++; } printf("%d %d %d %d",english,num,space,other); return 0; }
0.0分
2 人评分