我想做一个漂亮的词云,就像这样:
these are
words
floating
我计算了每个单词的第一个字母的(x,y)
-coordinates,将它们插入到我的word云生成器中,让它完成它的工作。但是,我意外地使用了(y,x)
-coordinates,因此结果如下所示:
these
floating
words
are
因为我懒得重新计算坐标,所以我需要你帮我转一下云这个词。
您的输入是由小写ASCII字母和空格组成的矩形网格。这意味着每一行都填充有相同长度的空格。输入可以视为多行字符串或字符串数组。
单词是字母的水平段,其位置是最左边字母的(x,y)
-coordinates,网格的左上角是(0,0)
。总有至少一个单词,没有尾随行或空格列。但是,空格的前导行或列可能存在。
您的输出是另一个矩形字符网格,它是通过将带有(x,y)
位置的每个单词移动到(y,x)
位置获得的。您的输出不能包含额外的尾随行或空格列。必须保留前导行和列,并且输出必须是矩形的。
您可能会假设此转换不会创建重叠的单词,也不会将多个单词合并为一个。这意味着在输出上运行程序应该产生原始输入。
评分
您可以编写完整的程序或函数。最低字节数获胜,标准漏洞被禁止。
为了清晰起见(而且由于Stack不喜欢只有空格的行),每一行都以管道字符|
结尾。这些不是实际输入或输出的一部分,您应该删除它们。再次注意,在每个输出上运行程序也会产生相应的输入。
Input:
oneword|
Output:
oneword|
Input:
spaces|
Output:
|
|
spaces|
Input:
|
row|
Output:
row|
Input:
these are|
words |
|
floating |
Output:
these |
|
floating|
|
words |
|
|
|
are |
Input:
same|
the |
|
same |
Output:
same|
the |
|
same |
Input:
some |
words k|
|
|
|
still|
Output:
words |
|
some still|
|
|
|
k |
Input:
hello |
world hey|
what up |
Output:
what|
|
world|
hello |
|
|
|
up |
hey |
Input:
a b a d cc|
g h huh nng|
ye dunnn |
dud yo |
wha g |
huh heh hah|
Output:
|
g wha |
a ye huh|
h |
b dud |
dunnn |
huh heh|
a g |
|
d yo |
nng hah|
cc |
发布于 2021-01-25 06:44:16
{x←' '⍴⍨×⍨2/⌈/⍴⍵⋄(⌈⌿↑⍸' '≠x)↑x⊣{x⊢←(⊃⍵)@((⊃⌽⍵)∘+¨↓0,⍪1-⍨⍳≢⊃⍵)⊢x}¨↓(⊃,/' '(≠⊆⊢)¨↓⍵),⍪⌽¨⍸2{1 0≡' '=⍺⍵}/' ',⍵}
生成一个超大的空格矩阵,并使用@
添加所需的单词。然后,作物恢复到所需的大小。
https://codegolf.stackexchange.com/questions/74198
复制