什么是最简单的算法来查找一个给定年份的第零天的星期几? [英] What is the easiest algorithm to find the day of week of day zero of a given year?

查看:112
本文介绍了什么是最简单的算法来查找一个给定年份的第零天的星期几?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力弄清楚一个特定年份的零日(1月1日)的星期几。

I am trying to figure out what the day of the week of day zero (January 1st) of a given year.

到目前为止,我已经看过维基百科页面计算一周中的几天,但是我想知道如果您有一个最简单的算法

So far I have looked at the Wikipedia page 'Calculating the day of the week' but I was wondering if there is an easiest algorithm if you're just trying to find day zero.

推荐答案

在28年的周期里重复一次。将年份除以28,并返回相应的星期几(星期几的值存储在数组/向量中)。这将是最快最简单的算法。但是,对于读取代码的人来说,这种算法并不清楚。你的选择取决于你想要快速,简单还是明确地。

Years repeat on a 28 year cycle. Divide the year by 28 and return the respective day-of-the-week (the day-of-the-week values being stored in an array/vector). This would be the fastest and simplest algorithm. But this algorithm would not be at all clear to someone reading the code. Your choice depends on whether you want fast, simple or "clearly correct".

这篇关于什么是最简单的算法来查找一个给定年份的第零天的星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆