解题思路:没什么好写的
注意事项:
参考代码:
#include <stdio.h> #include <string.h>//为了调用strlen()函数 int main(void) { char s[100]; //定义数组用来储存字符串 gets(s); //输入带有空格的字符串s int alp = 0, spa = 0, dig = 0, oth = 0; //字母,空格,数字,其他 int len = strlen(s); //将len定义为s的长度 for (int i = 0; i < len; ++i) { if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))//若s[i]在A-Z或者a-z之间 alp++; else if (s[i] == ' ') spa++; else if (s[i] >= '0' && s[i] <= '9') dig++; else oth++; //这里else if的用法非常重要 } printf("%d\n%d\n%d\n%d", alp, spa, dig, oth);//分别打印出来,记得换行 return 0; }
0.0分
5 人评分