1. 程式人生 > >中國大學MOOC-C程序設計(浙大翁愷)—— 單詞長度

中國大學MOOC-C程序設計(浙大翁愷)—— 單詞長度

argc 其中 class 符號 urn 一行 scanf 輸入格式 see

題目內容:

你的程序要讀入一行文本,其中以空格分隔為若幹個單詞,以‘.’結束。你要輸出這行文本中每個單詞的長度。這裏的單詞與語言無關,可以包括各種符號,比如“it‘s”算一個單詞,長度為4。註意,行中可能出現連續的空格。

輸入格式:

輸入在一行中給出一行文本,以‘.’結束,結尾的句號不能計算在最後一個單詞的長度內。

輸出格式:

在一行中輸出這行文本對應的單詞的長度,每個長度之間以空格隔開,行末沒有最後的空格。

輸入樣例:

It‘s great to see you here.

輸出樣例:

4 5 2 3 3 4

 1 #include <stdio.h>
 2 #include <string
.h> 3 4 int main(int argc, const char * argv[]) { 5 6 char word[100]; 7 int i; 8 int n=1; 9 do 10 { 11 char c=.; 12 scanf("%s",word); 13 i=(int)strlen(word); 14 if(word[i-1]==c) 15 {if(i>1) 16 { 17 printf("
%d\n",i-1); 18 } 19 20 n=0; 21 } 22 else{ 23 printf("%d ",i); 24 } 25 }while(n); 26 return 0; 27 }

中國大學MOOC-C程序設計(浙大翁愷)—— 單詞長度