题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include<stdio.h>
#include<string.h>
int main(){
int count_eng=0,count_kong=0,count_num=0,count_other=0;
char str[1001]={'\0'};
while(scanf("%[^\n]",str)>0){
for(int i=0;i<strlen(str);i++){
if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))
count_eng=count_eng+1;
else if(str[i]==' ')
count_kong=count_kong+1;
else if(str[i]>='0'&&str[i]<='9')
count_num=count_num+1;
else
count_other=count_other+1;
}
}
printf("%d\n%d\n%d\n%d",count_eng,count_kong,count_num,count_other);
}
#include<string.h>
int main(){
int count_eng=0,count_kong=0,count_num=0,count_other=0;
char str[1001]={'\0'};
while(scanf("%[^\n]",str)>0){
for(int i=0;i<strlen(str);i++){
if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))
count_eng=count_eng+1;
else if(str[i]==' ')
count_kong=count_kong+1;
else if(str[i]>='0'&&str[i]<='9')
count_num=count_num+1;
else
count_other=count_other+1;
}
}
printf("%d\n%d\n%d\n%d",count_eng,count_kong,count_num,count_other);
}