sscanf 你會用嗎?
Description
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
Sample Input
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
Sample Output
cat
eh
loops
看到這個輸入了嗎?你有更好的處理方法嗎?
說實在的我真的對這個有點蛋庝呀。
然而,自從認識了sscanf以后,心里就爽快多了。
到底如何使用sscanf呢?聽我慢慢道來……
就針對第一行了輸入dog ogday來說,
我們用gets(c)來存入dog ogday這個字符串,
接下來就該sscanf上場了。
sscanf(c,"%s%s", a, b);
這個時候,我們可以看到a=dog; b=ogday;
對了,被你說中了,sscanf的作用就是拆分。
將c拆分成兩個子串。
難道只可以拆成兩個個子串嗎?
答案是否定的。
要拆成幾個就要根據你的輸入了。
也就是說可以是三個,四個,五個……
好了,就說到這里吧!
posted on 2011-10-02 17:21 More study needed. 閱讀(248) 評論(0) 收藏 舉報
浙公網安備 33010602011771號