Huang: "sword refers to offer: Famous enterprise interviewer explaining typical programming problem": Nine degrees OJ title description: http://ac.jobdu.com/problem.php?cid=1039&pid=25 Jobdu recently arrived with a new employee, fish, who always takes an English magazine in the morning and writes some sentences in the book. Colleague Cat was interested in what Fish wrote, one day he borrowed it from fish, but couldn't read it. For example, "student. A am I ". Later realized that this guy turned the sentence in the order of words, the correct sentence should be "I am a student." Cat one by one flip these word order is not good, can you help him. input: Each test case is one line, which represents an English sentence. We guarantee that the number of words in a sentence will not exceed 600, and the length of each word will not exceed 30. But it's important to note that fish is a sloppy person, and sometimes there are a lot of spaces in the middle of two words. For convenience, you can assume that the total number of characters in a line is no more than 50,000, and that punctuation can be treated like ordinary letters. output: corresponding to each test case, the correct sentence after the reversal of the output line alone. Sample Input:
Student. A am I
i ' m a freshman and I like jobdu!
Sample output:
I am a student.
jobdu! Like I and freshman a I ' m
Thought: For example, everyone will know. Example: Input 123 456 789
We'll flip each string 321 654 987
Then the overall flip 789 456 123 OK, the effect achieved.
In fact, the last time the flip is not required, directly from the forward output character is ok.
Code AC:
#include <stdio.h> #include <string.h> int main () {char str[50001], ch;
int I, low, High, TMP, Len;
while (gets (str)) {low = 0;
High = 0;
len = strlen (str);
while (Low < Len) {while (str[low] = = ") {
low++;
} high = low;
while (Str[high]) {if (Str[high] = = ") {
high--;
Break
} else {high++;
}} if (Str[high] = = ' + ') {high--;
} TMP = high + 1; WhiLe (Low < high) {ch = Str[low];
Str[low] = Str[high];
Str[high] = ch;
low++;
high--;
} low = tmp;
High = tmp;
} for (i = len-1; i > 0; i--) {printf ("%c", Str[i]);
} printf ("%c\n", str[0]);
} return 0;
}