-3
编写名为month_range的函数,该函数将一年中名为day_one和day_two的两天(例如65,128,假定年份为365天)作为输入并返回其月份的int列表。 这个中断列表的大小必须是day_two - day_one + 1;
意识到,如果day_one> day_two,列表的大小= 0如何获得一个月的两天的int列表?
例如:month_range(25,36) should return [1,1,1,1,1,1,1,2,2,2,2,2]
一月(25,26,27,...,31)和二月(1,2- ,..,5)
我写的代码,但它不工作:
fun month_range (day1:int,day2:int) =
let
val month_days= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
fun what_month(day :int) =
let
fun aux(sum :int, numbers: int list) =
let
val numbers_tail = tl numbers
in
if sum <= (hd numbers)
then 1
else
1 + aux(sum, (hd numbers + hd numbers_tail)::(tl numbers_tail))
end
in
aux(day, month_days)
end
in
if (day1>day2)
then []
else what_month(day1) @ what_month(day2)
end
欢迎来到StackOverflow。这不是“发布你的家庭作业,我们会为你编写代码”网站。请发布你自己试图解决这个问题的工作,解释它如何不按照你期望的方式工作,我们很乐意尝试并帮助你弄清楚为什么它不起作用。我们在这里没有为你做功课。如果您需要帮助了解问题的要求,请咨询您的教授或助教。祝你好运。 – 2013-04-04 23:05:50
你必须弄脏你的手。 – tarrsalah 2013-04-04 23:25:13
@tarrsalah,首先你将解决方案交给一个银盘([她之前的问题](http://stackoverflow.com/q/15787541/577513)),现在你让她变得“脏”...... – 2013-04-04 23:39:39