题目描述
编一个程序, 读入用户输入的, 以 "." 结尾的一行文字, 统计一共有多少个单词, 并分别输出每个单词含有多少个字符.
(凡是以一个或多个空格隔开的部分就为一个单词)
输入
输入包括 1 行字符串, 以 "." 结束, 字符串中包含多个单词, 单词之间以一个或多个空格隔开.
输出
可能有多组测试数据, 对于每组数据,
输出字符串中每个单词包含的字母的个数.
样例输入
hello how are you.
样例输出
- 5 3 3 3
- #include<cstdio>
- #include<string.h>
- int main(){
- char str[1000];
- while(NULL!=fgets(str,1000,stdin)){
- int count=0;
- int flag=1;
- for(int i=0;i<strlen(str);i++){
- if(str[i]!=''&&str[i]!='.'){
- count++;
- }else{
- if(count>0){
- printf("%d",count);
- count=0;
- }
- }
- }
- printf("\n");
- }
- }
Mist Note: 多读读代码的思路.
来源: http://www.bubuko.com/infodetail-2946504.html