| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11262 | Sentence Reversal |
|
| 11263 | Word Count |
|
Description
In this problem, you are given several sentences, and you have to print the reversal of each of them.
A reversal of a sentence is the reversed order of words in the original sentence. For example, for the input string "this is a book", the result should be "book a is this".
Hint 1: for the slides in the lecture, we suggest you to do the task by a recusive function. The function seeks the first word from current location, and call itself recursively. Before each return, the function will print the word it found. Then all words will be printed in the reversed order.
The function prototype is something like this:
void sentence_reversal( char *now ) ; // which seek the first word from *now, and pass an new *now location to the called function
And the resursion is like the following figure:
this (4th printed word)
-> is (3rd printed word)
-> a (2nd printed word)
-> book (1st printed word)
Hint 2: Print the spaces between words, and there sould be no blanks (spaces) at the begin or the end of new setences. If the original setence has only one word, print the word directly without any spaces.
Note: Another method to solve this problem is seeking words from the end of the original setence. But we strongly recommend you to try the recursive way as a practice.
Input
There are several lines of input, and each line presents a setence.
No lines are longer than 500 characters, and any empty lines in the input should be skipped. At most 10 sentences will appear in a test case.
Words in setences are seperated by a space (' '). There will be no continuous spaces, or any spaces at the begin or end of the setences.
Output
Print each reversal sentence, and separate them by the new line symbol ('\n'). All words in a reversal sentence are seperate by a space.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an article as input. You have to count the number of each word, and prints the list of words in alphabetical order.
An article is made of paragraphs and words. In this problem, Word Count refers to an useful tool that counts the numbers of appearances of different words in an article. In this problem, we have provide a function that parse the input article and fetch each word. Slightly different from other partial judge you have seem before, your submission should have a main function and all memory you need, and include the "function.h" to use our fetch_word() function. Function fetch_word() is define as following:
const char *fetch_word() ;
Each time you call this function, it returns a const pointer which points to the address of a word, and make sure the end of the returned word is ended by character '\0'. Typically, you have to copy characters from the returning value of fetch_word() to your 2D array (or other memory layout) if necessary, and increase the counter for the specific word. If there is no more words in a article, the function returns NULL, and you should start preparing output the results.
Note: If you try to use a pointer to safe the return value, remember to use the const char* type, like "const char* word = fetch_word();".
After you count the numbers of words, you should sort and print all words as a report. The format will be describeb in Output.
Input
Input is an article. Words are splited by blanks (spaces, tab and new line) and some punctuations(標點符號). The whole input contains only one ariticle. There are no more than 100 different words in a ariticle, and no words are longer than 30 characters.
Output
Print the pair <word number> in each line like the sample output, and seperate word and number by a space. All words should be count as all characters is lowercase(英文小寫). Non-alphabetical characters (like numbers and punctuations) just remain the same. You just have to count all words we fetch for you.