#include <cstdio>
#include <cstring>
#include <cctype>
char* trim(char *str){
while (*str == ' '){
++str;
}
return str;
}
int main(){
int n = 0;
int len = 0;
int sum = 0;
char buf[200];
memset(buf, '\0', sizeof(buf));
fgets(buf, sizeof(buf), stdin);
char *tmp = buf;
while (*tmp != '\0'){
tmp = trim(tmp);
len = 0;
while (isalpha(*tmp++)){
++len;
}
sum += len;
++n;
}
printf("n=%d, avglen=%d\n", n, sum / n);
return 0;
}
算法竞赛入门经典 习题3-2单词们的平均长度
最新推荐文章于 2023-03-09 21:29:10 发布