-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathNobita and String.py
More file actions
26 lines (20 loc) · 880 Bytes
/
Nobita and String.py
File metadata and controls
26 lines (20 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'''
Doraemon gave Nobita a gadget that swaps words inside a string in the following manner :
If there are W words, word 1 is swapped with word W, word 2 is swapped with word W-1 and so on. The problem is that Nobita himself cannot verify the answer for large strings. Help him write a program to do so.
INPUT :
the first line of the input contains the number of test cases. Each test case consists of a single line containing the string.
OUTPUT :
output the string with the words swapped as stated above.
CONSTRAINTS :
|string length| <= 100000
string contains english alphabets and spaces
SAMPLE INPUT
1
hello world
URL: https://www.hackerearth.com/practice/algorithms/string-algorithm/basics-of-string-manipulation/practice-problems/algorithm/nobita-and-string-4/
'''
t = int(raw_input())
while t>0:
s = raw_input()
print ' '.join((s.split(' '))[::-1])
t-=1