题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <stdio.h>
int main() {
char c;
int enCount=0;
int spCount=0;
int nuCount=0;
int otCount=0;
while(scanf("%c",&c)&&c!='\n'){
if(c>='a'&&c<='z'||c>='A'&&c<='Z'){
enCount++;
}
else if(c>='0'&&c<='9'){
nuCount++;
}
else if(c==' '){
spCount++;
}
else{
otCount++;
}
}
printf("%d\n%d\n%d\n%d\n",enCount,spCount,nuCount,otCount);
return 0;
}
逐个获取字符,分别根据ASCII统计,最后输出即可。
曼迪匹艾公司福利 95人发布
查看6道真题和解析