In a distributed system, log entries are crucial for debugging and monitoring. Imagine a scenario where a faulty logging agent sometimes records the key parameters of an event in reverse chronological or logical order within a single log line. Your task is to develop a utility that corrects these log entries by reversing the order of their essential segments (words) to restore the intended sequence.
A segment is defined as a sequence of non-space characters. In the corrupted log entries, segments are guaranteed to be separated by exactly one space. There will be no leading or trailing spaces in any log entry.
Consider a corrupted log entry: "status initiated process 1234"
The correct, reversed order should be: "1234 process initiated status"
The first line contains an integer T, denoting the number of test cases.
For each test case, a single line follows, containing the string s which represents a corrupted log entry.
For each test case, output a single line containing the corrected log entry, with its segments reversed in order.
1 <= T <= 1001 <= length of s <= 10^4s is either a lowercase English alphabet or a space.1 <= T <= 100; 1 <= length of s <= 10^4
Sample Input Demonstration
3 event id 456 failure system boot completed aloneStep-by-step Explanation of Sample 1:
Input:
"event id 456 failure"
- The segments are:
"event","id","456","failure".- Reversing their order gives:
"failure","456","id","event".- Joining them back with a single space results in:
"failure 456 id event".Step-by-step Explanation of Sample 2:
Input:
"system boot completed"
- Segments:
"system","boot","completed".- Reversed order:
"completed","boot","system".- Joined:
"completed boot system".Step-by-step Explanation of Sample 3:
Input:
"alone"
- Segments:
"alone".- Reversed order:
"alone".- Joined:
"alone".Expected Output:
failure 456 id event completed boot system alone
String & Tries
Adobe, Amazon, Apple, Cisco, Facebook, Goldman Sachs, MakeMyTrip, Microsoft, Paytm, Samsung, Sap Labs
Start coding and your submissions will appear here.