题解 | #统计单词#
统计单词
https://www.nowcoder.com/practice/11c6e7c9987c4ab48f8cdd8834c27064
#include<stdio.h>
#define Maxsize 100
int judge(char a){
if(a>=97&&a<123) return 1;
else return 0;
}
int countw(char a[]){
int i = 0,count = 0;
while(a[i]!='\0'){
if(judge(a[i]) && a[i+1]==' '){
count++;
}
i++;
}
return count+1;
}
int main(){
char str[Maxsize];
gets(str);
int count = 0,i = 0;
count = countw(str);
int ccount[Maxsize] = {0};
int j = 0;
while(str[j]!='\0'&&str[j]!='.'){
if(judge(str[j])){
ccount[i]++;
if(str[j+1]==' '||str[j+1]=='.'){
i++;
}
}
j++;
}
for(i=0;i<count;i++){
printf("%d ",ccount[i]);
}
return 0;
}
