24:单词的长度

24:单词的长度

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

输入一行单词序列,相邻单词之间由1个或多个空格间隔,请对应地计算各个单词的长度。 

注意,如果有标点符号(如连字符,逗号),标点符号算作与之相连的词的一部分。没有被空格间开的符号串,都算作单词。

输入
一行单词序列,最少1个单词,最多300个单词,单词之间用至少1个空格间隔。单词序列总长度不超过1000。
输出
依次输出对应单词的长度,之间以逗号间隔。
样例输入
She was born in 1990-01-02  and  from Beijing city.
样例输出
3,3,4,2,10,3,4,7,5
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 using namespace std;
 6 char a[10001];
 7 char b[10001];
 8 int main()
 9 {
10     int flag=0;
11     gets(a);
12     int l=strlen(a);
13     int tot=0;
14     for(int i=0;i<l;i++)
15     {
16         if(a[i]!=' ')tot++;
17         
18         else 
19         {
20             if(tot!=0)
21             {
22                 cout<<tot<<",";
23             }
24             tot=0;
25         }
26         if(i==l-1)
27             cout<<tot;
28         
29     }
30     return 0;
31 }

 

posted @ 2017-03-01 10:19  自为风月马前卒  阅读(1468)  评论(0编辑  收藏  举报

Contact with me