你的程序要讀入一行文本,其中以空格分隔為若干個單詞,以‘.’結束。你要輸出這行文本中每個單詞的長度。這裡的單詞與語言無關,可以包括各種符號,比如“it's”算一個單詞,長度為4。注意,行中可能出現連續的空格。
輸入格式:
輸入在一行中給出一行文本,以‘.’結束,結尾的句號不能計算在最後一個單詞的長度內。
輸出格式:
在一行中輸出這行文本對應的單詞的長度,每個長度之間以空格隔開,行末沒有最後的空格。
輸入樣例:
It's great to see you here.
輸出樣例:
4 5 2 3 3 4
#include <stdio.h>
#define M 1000
int main()
{
int count,i;
int flag = 1;
char word[M];
gets(word);
count = i = 0;
while(1)
{
if(count && (word[i] == ' ' || word[i] == '.'))//最後一個單詞可能為空格或'.'
{
if(flag == 1)//標記,第一次輸出
{
printf("%d",count);
flag ++;
}
else
printf(" %d",count);
count = 0;
}
while(word[i]==' ')//可能有多個空格
{
i ++;
}
if(word[i] == '.')
{
printf("\n");
break;
}
count ++;
i ++;
}
return 0;
}
//測試樣例:
//It's great to see you here.
//4 5 2 3 3 4
// It's g ~reat t**(o s^%7e+ you here .//great之間隔Table鍵
// 4 7 5 6 3 4