介绍
昨天我看到一个生日难题。恭喜!!
同样在这周,我看了电视节目《骨头》中的一集,其中发现一具尸体被埋在树下。为了计算死亡时间,他们计算了年轮。
之所以形成年轮,是因为树木在冬季生长较慢,在夏季生长较快。因此,您可以通过计算环数来计算树的年龄。您还可以看到自然事件,例如雨季或旱季。
挑战
给定一个整数n >= 1
作为输入,编写一个完整的程序以输出树龄轮。
由于环的形状会发生变化,因此请使用三个不同的字符(“ 0”,“ *”,“ +”)来显示气候周期。
1岁
0
2岁
***
*0*
***
3岁
+++++
+***+
+*0*+
+***+
+++++
4岁
0000000
0+++++0
0+***+0
0+*0*+0
0+***+0
0+++++0
0000000
树的大小是边的平方 2*n - 1
获奖
以字节为单位的最短代码获胜。
('0', '*', '+')
所以5年是*