Problem Statement
Example:
Input Sentence: "Hello, I am Aadil!"
The expected output will print, ",olleH I ma !lidaA".
The first and only line of input contains a string without any leading and trailing spaces. The input string represents the sentence given to Aadil.
The only line of output prints the sentence(string) such that each word in the sentence is reversed.
Constraints:
0 <= N <= 10^6
Where N is the length of the input string.
Time Limit: 1 second
Sample Input 1:
Welcome to Coding Ninjas
Sample Output 1:
emocleW ot gnidoC sajniN
Sample Input 2:
Always indent your code
Sample Output 2:
syawlA tnedni ruoy edoc
from sys import stdin
def reverseEachWord(string) :
lis=list(string[::-1].split())[::-1]
str=""
for i in lis:
str+=i
str+=' '
return str
#Your code goes here.
#main
string = stdin.readline().strip()
ans = reverseEachWord(string)
print(ans)
Comments
Post a Comment