Reverse word [BOJ 9093]

HyunMin Yang·2022년 9월 10일
1
post-thumbnail


For example:

If there is a sentence, Reverse the sentence's alphabets and print it.
The sentence "I am happy today", is going to be "I ma yppah yadto".

Code:

import sys
input = sys.stdin.readline

for i in range(int(input())):
    for j in input().split():
        print(j[::-1], end = " ")
    print()

We first import the system. We put .readline into a variable called input.

import sys
input = sys.stdin.readline

We use for statement to get how many inputs we will get

for i in range(int(input())):

We use a different for statement and get the input of the sentences. While doing that, we get the input of each words in the sentence and keep it in a list. We then reverse the words.

for j in input().split():
    print(j[::-1], end = " ")
print()
profile
Hello World!

0개의 댓글