Rust打印The Twelve Days of christmas歌词
1、网上搜了下歌词,歌词原文如下:
The Twelve Days Of Christmas - Songtime Kids
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 eveth 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 golden Rings
Four calling birds
Three French hens
Two turtle doves
And a partridge in a pear tree
On the Twelve 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 golden Rings
Four calling birds
Three French hens
Two turtle doves
And a partridge in a pear tree
2、分析一下歌词内容,大概需要嵌套循环来解决问题,代码如下:
fn main() {
let count = [
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"tenth", "eveth", "Twelve",
];
println!("The Twelve Days of christmas - Songtime Kids");
for i in 0..count.len() {
println!(
"On the {} day of Christmas
\rMy true love sent to me",
count[i]
);
if i == 0 {
println!("A partridge in a pear tree");
continue;
}
for j in 0..=i {
match i - j {
0 => println!("And a partridge in a pear tree"),
1 => println!("Two turtle doves"),
2 => println!("Three French hens"),
3 => println!("Four calling birds"),
4 => println!("Five golden Rings"),
5 => println!("Six geese a-laying"),
6 => println!("Seven swans a-swimming"),
7 => println!("Eight maids a-milking"),
8 => println!("Nine ladies dancing"),
9 => println!("Ten Lords a Leaping"),
10 => println!("Eleven Pipers Piping"),
11 => println!("Twelve Drummers Drumming"),
_ => (),
}
}
}
}