使程序从STDIN的文件中获取列表,并很好地对齐它,就像coreutils中的ls命令一样。例如,假设下面的列表(以来自ASCII大学为例,它发生在该站点的聊天室中)。
alligator
ant
bear
bee
bird
camel
cat
cheetah
chicken
chimpanzee
cow
crocodile
deer
dog
dolphin
duck
eagle
elephant
fish
fly
fox
frog
giraffe
goat
goldfish
hamster
hippopotamus
horse
kangaroo
kitten
leopard
lion
lizard
llama
lobster
monkey
octopus
ostrich
otter
owl
oyster
panda
parrot
pelican
pig
pigeon
porcupine
puppy
rabbit
rat
reindeer
rhinoceros
rooster
scorpion
seal
shark
sheep
shrimp
snail
snake
sparrow
spider
squid
squirrel
swallow
swan
tiger
toad
tortoise
turtle
vulture
walrus
weasel
whale
wolf
zebra对齐结果,如下面的示例所示(示例显示列设置为80)。接收终端宽度作为第一个参数。如果任何论点比这个论点更大,你可以做任何事情。尝试使用尽可能多的列与两个空格分隔符,只要没有溢出。
alligator crocodile giraffe llama pig shark tiger
ant deer goat lobster pigeon sheep toad
bear dog goldfish monkey porcupine shrimp tortoise
bee dolphin hamster octopus puppy snail turtle
bird duck hippopotamus ostrich rabbit snake vulture
camel eagle horse otter rat sparrow walrus
cat elephant kangaroo owl reindeer spider weasel
cheetah fish kitten oyster rhinoceros squid whale
chicken fly leopard panda rooster squirrel wolf
chimpanzee fox lion parrot scorpion swallow zebra
cow frog lizard pelican seal swan发布于 2014-01-06 18:01:51
n%:I{)I/{{,}$-1=,}:L%{2++}*"#{ARGV[0]}"~)<}I,,?)/{.L{:x' '*+x<}+%}%zip{' '*n}/假设列之间有两个空格(尽管可以很容易地更改为一个保存2个字符的空格)。
https://codegolf.stackexchange.com/questions/17791
复制相似问题