Ask Question
8 November, 19:26

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.

+2
Answers (1)
  1. 8 November, 20:14
    0
    Python 3 code:

    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])
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers