圣诞十二日
* * * *
拉格朗日计划
* * * *
圣诞十二日

打印歌曲《圣诞节的十二天》的歌词。

歌词如下:

On the First day of Christmas
My true love sent to me
A Partridge in a Pear Tree.

On the Second day of Christmas
My true love sent to me
Two Turtle Doves, and
A Partridge in a Pear Tree.

On the Third day of Christmas
My true love sent to me
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree.

On the Fourth day of Christmas
My true love sent to me
Four Calling Birds,
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree.

On the Fifth day of Christmas
My true love sent to me
Five Gold Rings,
Four Calling Birds,
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree. 

On the Sixth day of Christmas 
My true love sent to me 
Six Geese-a-Laying, 
Five Gold Rings, 
Four Calling Birds, 
Three French Hens, 
Two Turtle Doves, and 
A Partridge in a Pear Tree. 

On the Seventh day of Christmas 
My true love sent to me 
Seven Swans-a-Swimming, 
Six Geese-a-Laying, 
Five Gold Rings, 
Four Calling Birds, 
Three French Hens, 
Two Turtle Doves, and
A Partridge in a Pear Tree. 

On the Eighth day of Christmas 
My true love sent to me 
Eight Maids-a-Milking,
Seven Swans-a-Swimming,
Six Geese-a-Laying,
Five Gold Rings,
Four Calling Birds,
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree.

On the Ninth day of Christmas
My true love sent to me
Nine Ladies Dancing,
Eight Maids-a-Milking,
Seven Swans-a-Swimming,
Six Geese-a-Laying,
Five Gold Rings,
Four Calling Birds,
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree.

On the Tenth day of Christmas
My true love sent to me
Ten Lords-a-Leaping,
Nine Ladies Dancing,
Eight Maids-a-Milking,
Seven Swans-a-Swimming,
Six Geese-a-Laying,
Five Gold Rings,
Four Calling Birds,
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree.

On the Eleventh day of Christmas
My true love sent to me
Eleven Pipers Piping,
Ten Lords-a-Leaping,
Nine Ladies Dancing,
Eight Maids-a-Milking,
Seven Swans-a-Swimming,
Six Geese-a-Laying,
Five Gold Rings,
Four Calling Birds,
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree.

On the Twelfth day of Christmas
My true love sent to me
Twelve Drummers Drumming,
Eleven Pipers Piping,
Ten Lords-a-Leaping,
Nine Ladies Dancing,
Eight Maids-a-Milking,
Seven Swans-a-Swimming,
Six Geese-a-Laying,
Five Gold Rings,
Four Calling Birds,
Three French Hens,
Two Turtle Doves, and
A Partridge in a Pear Tree.


本题难度:



解答

歌词共12段,段落之间以空行分割。每段第一句的序数词不同,第k段结尾有k句话,依次重复从第1天到第k天的礼物。

主要是数词和序数词只有轻微的差异不容易处理,此处直接生成两个数组调用,代码只有一行。

代码长度:468字节 vs. 全站第一:415字节。

for i in range(12):*map(print,[f"On the {'First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth'.split()[i]} day of Christmas\nMy true love sent to me"]+('Twelve Drummers Drumming,~Eleven Pipers Piping,~Ten Lords-a-Leaping,~Nine Ladies Dancing,~Eight Maids-a-Milking,~Seven Swans-a-Swimming,~Six Geese-a-Laying,~Five Gold Rings,~Four Calling Birds,~Three French Hens,~Two Turtle Doves, and~A Partridge in a Pear Tree.~').split('~')[11-i:]),