| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11278 | print linked list |
|
| 11279 | Sentence Reversal |
|
Description
Given a link list structure named Node.
typedef struct _Node {
int data;
struct _Node *next;
} Node;
Use this structure to implement a linked list printing.
You will be provided with main.c and function.h, and asked to implement function.c.
For OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose c compiler)
Step 2. Check the results and debug your program if necessary.
Input
The input contains a sequence of positive integers as the linklist and the order, except the last one, which is -1, indicating the end of the sequence.
Output
The output contains the sequence of resulting linklist. All integers are seperate by a space. Note that there is a new line ('\n') character at the end of the output.
Sample Input Download
Sample Output Download
Partial Judge Code
11278.cPartial Judge Header
11278.hTags
Discuss
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".
You have to upload the complete source code to solve this problem.
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 one line in the input, which presents a setence.
No lines are longer than 100 characters, and any empty lines in the input should be skipped.
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 the reversed sentence. There should be a new line symbol ('\n') at the end of output.
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.