c program string 一問

2008-04-20 9:20 pm
點可以將一句句子reverse order

example :
enter a sentence :i go to school
reverse order > school to go i

回答 (2)

2008-04-21 4:55 am
✔ 最佳答案
If you do not have to use stacks to do, here's an example of complete code:
http://hk.knowledge.yahoo.com/question/question?qid=7008040501636
If you have to use stacks, and still haven't mastered how to do it, PM me.

2008-04-21 03:33:09 補充:
I have written a program using gets() and manipulation of a character string to do just what you need. The source is a little long to be presented here, but is available under the heading of this question at:
http://mathmate.brinkster.net/programming.htm
2008-04-20 10:07 pm
Exactly 既 code syntax 同 functions for C 我唔記得lu.
不過可以比個 sudo code 或者 hints 你作參考:

Step 1. 將整句 Sentence Split by space, 擺落 array 到
sWord() = Split(sSentence, ,,)
e.g.
sSentence : i go to school
sWord(0) : i
sWord(1) : go
sWord(2) : to
sWord(3) : school

Step 2. 將 array 由尾 loop 番上頂, 每個loop入面 append 一個space
for (i=sWord.Length-1; i>=0; i--)
{
sReverseOrder = strcat(sReverseOrder, sWord(i))
sRerversOrder = strcat(sReverseOrder, ,,)
{

Step 3. Trim 左 sReverseOrder 或者 delete sReverseOrder 最尾既 space.

你要既結果就係 sReverseOrder 喇.

HopeThisHelp.


收錄日期: 2021-04-13 15:27:23
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080420000051KK01360

檢視 Wayback Machine 備份