Question

You are given an integer N, followed by N lines of input (1 <= N <=...

You are given an integer N, followed by N lines of input (1 <= N <= 100). Each line of input contains one or several words separated with single spaces. Each word is a sequence of letters of English alphabet containing between 1 and 10 characters, inclusive. The total number of words in the input is between 1 and 100, inclusive.

Your task is to reverse the order of words in each line of input, while preserving the words themselves. The lines of your output should not have any trailing or leading spaces.

Example

input
3
Hello World
Bye World
Useless World

output
World Hello
World Bye
World Useless

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python3 code for above problem is:-

n = int(input())
rev_str = [ ]


for i in range(n):
    s = str(input())
    s.split()
    words = s.split(' ')
    string = [ ]
      
    for word in words:
        string.insert(0, word)
  
    rev_str.append(" ".join(string))
      
    #print(" ".join(string))
for i in range(len(rev_str)):
    print(rev_str[i])

Attached screenshot for sample output

Add a comment
Know the answer?
Add Answer to:
You are given an integer N, followed by N lines of input (1 <= N <=...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT