为了平衡具有内置日期库的语言和没有内置日期库的语言之间的竞争环境,让我们使用虚拟日历。“被遗忘的境界”是“龙与地下城” 的(the?)广告系列设置。当然,每个人都有自己的日历。
Harptos日历
方便地,在“被遗忘的领域”中的一年也有365天。此外,日历也有12个月。但是,这才变得有趣。每个月正好是30天。剩下的5天是假期,介于两个月之间。以下是月份和节假日的顺序(节假日缩进):
1 Deepwinter
Midwinter
2 The Claw of Winter
3 The Claw of the Sunsets
4 The Claw of the Storms
Greengrass
5 The Melting
6 The Time of Flowers
7 Summertide
Midsummer
[Shieldmeet]
8 Highsun
9 The Fading
Highharvestide
10 Leaffall
11 The Rotting
The Feast of the Moon
12 The Drawing Down
请注意,我在括号中插入了第六个假期。这是the年,仅每四年发生一次(是的,仅此而已–几个世纪以来没有其他恶作剧)。
有关月份名称的旁注:每个月都有一个正式名称和通用名称。以上是通用名称。我选择这些是因为我认为它们允许进行更有趣的压缩。
几年中有几种编号,但是最广泛的一种是Dalereckoning,简称为DR。(此外,每年都有一个或多个名称,但我们不会为此烦恼。)
日期的组成部分应以逗号和空格分隔。总而言之,有效日期可能如下所示:
4, The Melting, 1491 DR
要么
Shieldmeet, 1464 DR
请注意,假期没有天数。(我想4th of The Melting
这几个月的日子会更好,但我不想将序数拖入其中。)
脚注:当xnor抱怨每个单日挑战都需要the年计算时,我想到了这一点。我无法完全消除它,但是至少在此日历中它只是一个模。
挑战
给定Harptos日历的有效日期以及整数D
,则在D
几天后输出日期。请注意,该值D
可能为负,在这种情况下,您应该返回D
几天前的日期。
您可以编写程序或函数,通过STDIN(或最接近的替代方案),命令行参数或函数自变量获取输入,并通过STDOUT(或最接近的替代方案),函数返回值或函数(out)参数输出结果。
您可以假设年份为正且小于2000。
适用标准代码高尔夫球规则。
测试用例
前十个左右的测试用例应该测试假期和leap年附近的所有边缘情况。下一组将测试跨多年工作的范围,并且已实施了所有月份和节假日。下半年再次是所有相同的测试用例,但偏移量为负。
"30, Summertide, 1491 DR" 1 => "Midsummer, 1491 DR"
"30, Summertide, 1491 DR" 2 => "1, Highsun, 1491 DR"
"Midsummer, 1491 DR" 1 => "1, Highsun, 1491 DR"
"30, Summertide, 1492 DR" 1 => "Midsummer, 1492 DR"
"30, Summertide, 1492 DR" 2 => "Shieldmeet, 1492 DR"
"30, Summertide, 1492 DR" 3 => "1, Highsun, 1492 DR"
"Midsummer, 1492 DR" 1 => "Shieldmeet, 1492 DR"
"Midsummer, 1492 DR" 2 => "1, Highsun, 1492 DR"
"Shieldmeet, 1492 DR" 1 => "1, Highsun, 1492 DR"
"1, Highsun, 1490 DR" 365 => "1, Highsun, 1491 DR"
"1, Highsun, 1491 DR" 365 => "Shieldmeet, 1492 DR"
"Shieldmeet, 1492 DR" 365 => "Midsummer, 1493 DR"
"Midsummer, 1493 DR" 365 => "Midsummer, 1494 DR"
"Shieldmeet, 1500 DR" 365 => "Midsummer, 1501 DR"
"14, Deepwinter, 654 DR" 5069 => "The Feast of the Moon, 667 DR"
"Midwinter, 17 DR" 7897 => "15, The Fading, 38 DR"
"3, The Claw of Winter, 1000 DR" 813 => "25, The Claw of the Storms, 1002 DR"
"Greengrass, 5 DR" 26246 => "9, The Claw of the Sunsets, 77 DR"
"30, The Melting, 321 DR" 394 => "29, The Time of Flowers, 322 DR"
"17, The Time of Flowers, 867 DR" 13579 => "20, Highsun, 904 DR"
"Highharvestide, 1814 DR" 456 => "30, The Drawing Down, 1815 DR"
"23, The Rotting, 1814 DR" 3616 => "16, Leaffall, 1824 DR"
"1, Deepwinter, 1 DR" 730499 => "30, The Drawing Down, 2000 DR"
"Midsummer, 1491 DR" -1 => "30, Summertide, 1491 DR"
"1, Highsun, 1491 DR" -2 => "30, Summertide, 1491 DR"
"1, Highsun, 1491 DR" -1 => "Midsummer, 1491 DR"
"Midsummer, 1492 DR" -1 => "30, Summertide, 1492 DR"
"Shieldmeet, 1492 DR" -2 => "30, Summertide, 1492 DR"
"1, Highsun, 1492 DR" -3 => "30, Summertide, 1492 DR"
"Shieldmeet, 1492 DR" -1 => "Midsummer, 1492 DR"
"1, Highsun, 1492 DR" -2 => "Midsummer, 1492 DR"
"1, Highsun, 1492 DR" -1 => "Shieldmeet, 1492 DR"
"1, Highsun, 1491 DR" -365 => "1, Highsun, 1490 DR"
"Shieldmeet, 1492 DR" -365 => "1, Highsun, 1491 DR"
"Midsummer, 1493 DR" -365 => "Shieldmeet, 1492 DR"
"Midsummer, 1494 DR" -365 => "Midsummer, 1493 DR"
"Midsummer, 1501 DR" -365 => "Shieldmeet, 1500 DR"
"The Feast of the Moon, 667 DR" -5069 => "14, Deepwinter, 654 DR"
"15, The Fading, 38 DR" -7897 => "Midwinter, 17 DR"
"25, The Claw of the Storms, 1002 DR" -813 => "3, The Claw of Winter, 1000 DR"
"9, The Claw of the Sunsets, 77 DR" -26246 => "Greengrass, 5 DR"
"29, The Time of Flowers, 322 DR" -394 => "30, The Melting, 321 DR"
"20, Highsun, 904 DR" -13579 => "17, The Time of Flowers, 867 DR"
"30, The Drawing Down, 1815 DR" -456 => "Highharvestide, 1814 DR"
"16, Leaffall, 1824 DR" -3616 => "23, The Rotting, 1814 DR"
"30, The Drawing Down, 2000 DR" -730499 => "1, Deepwinter, 1 DR"