输入:
一串
输出:
1)首先,我们采取在输入串的末尾删除字符,直到我们留下的长度为正方形(即1,4,9,16,25,36,等等)
因此,abcdefghijklmnopqrstuvwxyz
(长度26)变为abcdefghijklmnopqrstuvwxy
(长度25)。
2)然后我们将其放在一个正方形中,从左到右一次一行:
abcde
fghij
klmno
pqrst
uvwxy
3)我们在四个方向上都将其折叠,如下所示(我们不断展开,直到外部折叠的“块”不再具有内部字符可展开):
m
qrs
l n
ghi
abcde
ihgf jihg
mn lk on lm
srqp tsrq
uvwxy
qrs
l n
ghi
m
需要注意的一些事情,当我们向外折叠时,我们基本上像这样镜像(为澄清起见添加了数字,这些数字表示这些示例中的“索引”):
当我们向外折叠时:
123 to: 321 123
fghij ihgf j
当我们折叠右侧时:
123 to: 123 321
fghij f jihg
当我们向上折叠时:
3q
2l
1g
b to: b
1g 1
2l 2
3q 3
v v
当我们向下折叠时:
b b
1g 1
2l 2
3q 3
v to: v
3q
2l
1g
挑战规则:
- 您可以假设输入将始终至少包含1个字符(也将是输出)。
- 输出格式很灵活,因此您可以打印到STDOUT或STDERR。返回为字符串数组/列表或字符二维数组;带换行符的单个字符串;等等
- 输入将仅包含字母数字字符(
a-zA-Z0-9
) - 您还可以使用非字母数字字符来填充ASCII美术输出中和/或周围的空格,例如点
.
。 - 尾随空格和一条尾随换行符是可选的。
- 我们继续展开,直到外侧的折叠“块”不再有中心展开。
通用规则:
- 这是代码高尔夫球,因此最短答案以字节为单位。
不要让代码高尔夫球语言阻止您使用非代码高尔夫球语言发布答案。尝试针对“任何”编程语言提出尽可能简短的答案。 - 标准规则适用于您的答案,因此您可以使用STDIN / STDOUT,具有正确参数的函数/方法和返回类型的完整程序。你的来电。
- 默认漏洞是禁止的。
- 如果可能的话,请添加一个带有测试代码的链接。
- 另外,如有必要,请添加说明。
测试用例:
Input: abcdefghijklmnopqrstuvwxy
Output:
m
qrs
l n
ghi
abcde
ihgf jihg
mn lk on lm
srqp tsrq
uvwxy
qrs
l n
ghi
m
Input: A
Ouput:
A
Input: ThisIsATest
Output:
I
Thi
Is sI
ATe
I
Input: HowAboutAVeryLongExampleWhichIsAlsoAnEvenSquareInsteadOfOddOneAndExceeds64Chars
Output:
An
ch
xamp
i I
o E
quar
steadO
S e
s v
h s
E l
VeryLo
HowAbout
oLyreVA noLyreV
xampl Eg el Examp
hci Is hW As hi Ihc
nAo Ev sl ev so EnA
quare Sn Ie Squar
Odaetsn fOdaets
OddOneAn
steadO
S e
s v
h s
E l
VeryLo
xamp
i I
o E
quar
An
ch
Input: Lenght7
Output:
Le
ng
Input: abc
Output:
a