s******n 发帖数: 876 | 1 面试题, fix it with O(1) algorithm.
有包子啊 | t****t 发帖数: 6806 | 2 这个还需要包子?
【在 s******n 的大作中提到】 : 面试题, fix it with O(1) algorithm. : 有包子啊
| g****n 发帖数: 14 | 3 抛砖引玉吧 :)
const int DAYS_80_99 = 20 * 365 + 5;
const int CYCLE_400 = 365 * 400 + 97;
const int CYCLE_100_L = 365 * 100 + 25;
const int CYCLE_100_N = 365 * 100 + 24;
const int CYCLE_4_L = 365 * 4 + 1;
const int CYCLE_4_N = 365 * 4;
// input: cDay - number of days since Jan 1, 1980.
// For Jan 1, 1980, cDay==0
// output: year, day (this first day of a year is represented as 0).
void year(int cDay, int& year, int& day)
{
int days = cDay;
int years = 1980;
if (days >= DAYS_80_99)
| s******n 发帖数: 876 | 4 this is too long. let's make Jan 1st 2001 as Day 0.
【在 g****n 的大作中提到】 : 抛砖引玉吧 :) : const int DAYS_80_99 = 20 * 365 + 5; : const int CYCLE_400 = 365 * 400 + 97; : const int CYCLE_100_L = 365 * 100 + 25; : const int CYCLE_100_N = 365 * 100 + 24; : const int CYCLE_4_L = 365 * 4 + 1; : const int CYCLE_4_N = 365 * 4; : // input: cDay - number of days since Jan 1, 1980. : // For Jan 1, 1980, cDay==0 : // output: year, day (this first day of a year is represented as 0).
|
|