题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <stdio.h>
int main() {
char str[1001];
int i=0,a[4]={0};
while ((str[i]=getchar())!='\n') {
if ((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')) {
a[0]++;
}
else if (str[i]==' ') {
a[1]++;
}
else if (str[i]>='0'&&str[i]<='9') {
a[2]++;
}
else {
a[3]++;
}
i++;
}
for (int j=0; j<4; j++) {
printf("%d\n",a[j]);
}
return 0;
}



查看26道真题和解析