Last active
April 23, 2016 05:47
-
-
Save xgao32/a1a23fca0aa3439f6edfa22eb6ab6c41 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# ACM 比赛 https://open.kattis.com/problems/secretmessage | |
import sys | |
import math | |
strings = [s.strip() for s in sys.stdin.readlines()] | |
for i in range(1,int(strings[0]) + 1): | |
# find input size for matrix and number of characters for each word in sentence | |
s = strings[i] | |
l = len(s) | |
m = int(math.pow(math.ceil(math.sqrt(l)),2)) | |
k = int(math.ceil(math.sqrt(l))) | |
lett = [] | |
# pad string | |
for j in range(m): | |
if j < len(s): | |
lett.append(s[j]) | |
else: | |
lett.append('*') | |
gl = [] | |
# append append nth character from last to first column | |
# big list | |
bl = [] | |
# first to last row | |
for row in range((k-1),-1,-1): | |
temp = [] | |
# first column to last column | |
for col in range(k): | |
temp.append(lett[((k)*row)+col]) | |
bl.append(temp) | |
# first to last | |
for j in range(k): | |
for ii in range(k): | |
if bl[ii][j] == '*': | |
# print bl[k][j] | |
continue | |
else: | |
gl.append(bl[ii][j]) | |
word = '' | |
word = word.join(gl) | |
print word | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment