题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <stdio.h>
#include<malloc.h>
#include<string.h>
int main() {
char* str = (char*)malloc(1000 * sizeof(char));
gets(str);
int i;
int yw = 0, kg = 0, sz = 0, other = 0;
int len = strlen(str);
for (i = 0; i < len; i++) {
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
yw++;
else if (str[i] >= '0' && str[i] <= '9')
sz++;
else if (str[i] == ' ')
kg++;
else
other++;
}
printf("%d\n", yw);
printf("%d\n", kg);
printf("%d\n", sz);
printf("%d\n", other);
}
C语言刷题 文章被收录于专栏
自己从头开始刷的C语言

查看10道真题和解析