AC日记——单词的长度 openjudge 1.7 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
来源
习题(7-7) 元培-From WHF
思路:
  水题模拟;
来,上代码:
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>

using namespace std;

int len,ans=0,num[301];

char word[1002];

int main()
{
    gets(word);
    len=strlen(word);
    int now=0;
    while(now<len)
    {
        if(word[now]==' ') while(word[now]==' ') now++;
        else
        {
            int cur_1=0;
            while(word[now]!=' ')
            {
                if(now>=len) break;
                cur_1++;
                now++;
            }
            num[++ans]=cur_1;
        }
        
    }
    printf("%d",num[1]);
    for(int i=2;i<=ans;i++) printf(",%d",num[i]);
    return 0;
}

 

posted @ 2016-11-26 22:13  IIIIIIIIIU  阅读(787)  评论(0编辑  收藏  举报