给定一个ASCII字符串,输出它的爆炸后缀。例如,如果字符串是abcde,则有5个后缀,排序从最长到最短:
abcde
bcde
cde
de
e然后每个后缀都会爆炸,这意味着每个字符被复制的次数与其在该后缀中的索引位置相同。例如,爆炸abcde的后缀,
abcde
12345
abbcccddddeeeee
bcde
1234
bccdddeeee
cde
123
cddeee
de
12
dee
e
1
e总之,abcde的爆炸后缀是
abbcccddddeeeee
bccdddeeee
cddeee
dee
e''
'a'
a
'bc'
bcc
c
'xyz'
xyyzzz
yzz
z
'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f
's p a c e'
s ppp aaaaa ccccccc eeeeeeeee
pp aaaa cccccc eeeeeeee
p aaa ccccc eeeeeee
aa cccc eeeeee
a ccc eeeee
cc eeee
c eee
ee
e发布于 2016-10-15 00:51:57
ṫJxJY在网上试试!或验证所有测试用例.
ṫJxJY Main link. Argument: s (string)
J Indices; yield I := [1, ..., len(s)].
ṫ Tail; get the suffixes of s starting at indices [1, ..., len(s)].
J Indices; yield I again.
x Repeat. The atom 'x' vectorizes at depth 1 (1D arrays of numbers/characters)
in its arguments. This way, each suffix t gets repeated I times, meaning
that the first character of t is repeated once, the second twice, etc.
If left and right argument have different lengths, the longer one is
truncated, so I can safely be applied to all suffixes.
Y Join, separating by linefeeds.发布于 2016-10-15 02:03:26
f=lambda s,i=0:s[i:]and-~i*s[i]+f(s,i+1)or s and'\n'+f(s[1:])备选案文63:
f=lambda s,b=1:s and f(s[:-1],0)+s[-1]*len(s)+b*('\n'+f(s[1:]))发布于 2016-10-15 06:26:41
@]Elyk:Erz:jac@w\在网上试试!
@]E E is a suffix of the Input
lyk The list [0, ..., length(E) - 1]
:Erz The list [[0th char of E, 0], ..., [Last char of E, length(E) - 1]]
:ja For all elements of that list, concatenate the Ith char I times to itself
c Concatenate the list into a string
@w Write followed by a line break
\ False: backtrack to another suffix of the Inputhttps://codegolf.stackexchange.com/questions/96271
复制相似问题