单词数统计

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41648259/article/details/88287604

题目描述

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

输入描述:

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

出描述:

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

示例1

输入

复制

hello how are you.

输出

复制

5 3 3 3

#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    while(cin>>str){
        if(str[str.length()-1]=='.'){
            cout<<str.length()-1<<" ";
            break;
        }
        cout<<str.length()<<" ";
    }
    cout<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41648259/article/details/88287604