Kattis Encoded Message Solution in Python 3.
If you want to look at the question of encoded message on kattis click on this Kattis Encoded Message.
How did I Solve it?
I have stored each row in reverse so that it will store the words in the column continuously. Then I printed the encoded message going through the column continuously.
The code for the encoded message of kattis in python 3 is given below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
#dans stores the decoded message | |
dans=[] | |
for i in range(eval(input())): | |
#message stores the encoded message | |
message=input() | |
dmessage=[] | |
#ans stores the reverse row encode message | |
ans=[] | |
for i in range(0,len(message),math.floor(math.sqrt(len(message)))): | |
text=message[i:i+math.floor(math.sqrt(len(message)))] | |
ans.append(text[::-1]) | |
for i in range(len(ans)): | |
for j in range(len(ans)): | |
dmessage.append(ans[j][i]) | |
dans.append(''.join(dmessage)) | |
for item in dans: | |
print(item) |
Nicely written la. :P
ReplyDeleteThank you Sonam la...
Delete