5705 - mid2_Exercise6_Sentence reversal
|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
Description
輸入一個英文句子字串
包含多個英文單字
每個英文單字之間用單個空白字元隔開
沒有其他標點符號
例如
用程式將上面的句子以單字為單位反轉
輸出
讀取輸入的字串可以用下面的方式
char a[100];
fgets(a, 99, stdin);
a[strlen(a)-1] = '\n';
不使用 scanf "%s" 讀取字串的原因是因為 scanf 讀到空白字元就會停止
用 fgets 則會讀到換行才停止
由於 fgets 會把換行字元也讀進來
所也要多一個步驟
a[strlen(a)-1] = '\n';
把換行字元去掉
Input
一串字串(由小寫字母組成且長度不超過100)
Output
反轉後結果
Tags