-
题目描述:
-
编一个程序,读入用户输入的,以“.”结尾的一行文字,统计一共有多少个单词,并分别输出每个单词含有多少个字符。
(凡是以一个或多个空格隔开的部分就为一个单词)
-
输入:
-
输入包括1行字符串,以“.”结束,字符串中包含多个单词,单词之间以一个或多个空格隔开。
-
输出:
-
可能有多组测试数据,对于每组数据,
输出字符串中每个单词包含的字母的个数。
-
样例输入:
-
hello how are you.
-
样例输出:
-
5 3 3 3
-
-
#include <iostream> #include <cstdio> using namespace std; char str[10000]; int main() { int num,i; while(cin.getline(str,10000,'\n')) { num=0; for(i=0;str[i]!='.';i++) { if(str[i]!=' ') { num++; }else { if(num!=0) cout<<num<<" "; num=0; } } cout<<num<<endl; } return 0; } /************************************************************** Problem: 1182 User: cucumber王子 Language: C++ Result: Accepted Time:20 ms Memory:1528 kb ****************************************************************/