1809: 统计单词

题目描述

编一个程序,读入用户输入的,以“.”结尾的一行文字,统计一共有多少个单词,并分别输出每个单词含有多少个字符。
(凡是以一个或多个空格隔开的部分就为一个单词)

输入

输入包括1行字符串,以“.”结束,字符串中包含多个单词,单词之间以一个或多个空格隔开。

输出

可能有多组测试数据,对于每组数据,
输出字符串中每个单词包含的字母的个数。

样例输入

hello how are you.

样例输出

5 3 3 3


 1 #include<cstdio>
 2 #include<string.h>
 3 int main(){
 4     char str[1000];
 5     while(NULL!=fgets(str,1000,stdin)){
 6         int count=0;
 7         int flag=1;
 8         for(int i=0;i<strlen(str);i++){
 9             if(str[i]!=' '&&str[i]!='.'){
10                 count++;
11             }else{
12                 if(count>0){
13                     printf("%d ",count);
14                     count=0;
15                 }
16             }
17         }
18         printf("\n");
19     }
20 } 

Mist Note:多读读代码的思路。

posted on 2019-02-07 10:16  Aldrich_2020  阅读(163)  评论(0编辑  收藏  举报