【JiuDu OJ 04】what day is Date?

简介: 【JiuDu OJ 04】what day is Date?

The problem is related in “Date”. After we contacted the basic problem about Date,the other questions will be solved through the basic of Date’s question.

The last time,I writed a Blog about Date,which is named “《How many days between the date to date?》.we could use the same methods to solve today’s problem.

Thinking:

what day is Date?we need Know:

  • what day is today?
  • How many days between the today to that days,This problem gived,You need to use mood 7.

一、Task

二、process of solute

We used the methods ,using the interval of days to solve this problems , in order to show a method of basic Date’s problems .

#include<stdio.h>
#include<string.h>
#define IsYeap(x) x%100!=0&&x%4==0 ||x%400==0?1:0
int DayOfMonth[13][2]=
        {
                0,0,
                31,31,
                28,29,
                31,31,
                30,30,
                31,31,
                30,30,
                31,31,
                31,31,
                30,30,
                31,31,
                30,30,
                31,31
        };
char MonthName[13][20]=
        {
                " ",
                "January",
                "February",
                "March",
                "April",
                "May",
                "June",
                "July",
                "August",
                "September",
                "October",
                "November",
                "December"
        };
char WeekName[7][20]=
        {
                "Sunday",
                "Monday",
                "Tuesday",
                "Wednesday",
                "Thursday",
                "Friday",
                "Saturday"
        };
int buf[3001][13][32];
struct Date
{
    int Day;
    int Month;
    int Year;
    void nextDay()
    {
        Day++;
        if(Day>DayOfMonth[Month][IsYeap(Year)])
        {
            Day=1;
            Month++;
            if(Month>12)
            {
                Month=1;
                Year++;
            }
        }
    }
};
int main()
{
    Date tmp;
    tmp.Day=1;
    tmp.Month=1;
    tmp.Year=0;
    int cnt=0;
    while(tmp.Year<3001)
    {
        buf[tmp.Year][tmp.Month][tmp.Day]=cnt;
        cnt++;
        tmp.nextDay();
    }
    int day,month,year;
    char Month[20];
    while(scanf("%d%s%d",&day,&Month,&year)!=EOF)
    {
        for(int i=1;i<13;i++)
        {
            if(strcmp(MonthName[i],Month)==0)
            {
                month=i;
                break;
            }
        }
        int k=buf[year][month][day]-buf[2018][12][31]+1;
        int j=(k%7+7)%7;
        printf("%s",WeekName[j]);
    }
}


目录
相关文章
|
6月前
leetcode-1154:一年中的第几天
leetcode-1154:一年中的第几天
35 0
|
Java
《剑指offer》题解——week3
《剑指offer》题解——week3
64 0
《剑指offer》题解——week3
|
存储 机器学习/深度学习 算法
《剑指offer》题解——week7
《剑指offer》题解——week7
62 0
《剑指offer》题解——week7
|
算法 Java 索引
《剑指offer》题解——week1
思路:定义一个哈希表,遍历一次数组,利用哈希表对每个元素进行标记。若当前元素被标记过了,则该元素重复。 **时间复杂度:**`O(n)` **方法二:原地交换** 主要思想是把每个数放到对应的位置上,即让 `nums[i] = i`。 前往后遍历数组中的所有数,假设当前遍历到的数是 `nums[i]=x`,那么: - 如果`x != i && nums[x] == x`,则说明 `x`出现了多次,直接返回 `x`即可; - 如果`nums[x] != x`,那我们就把 `x` 交换
92 0
《剑指offer》题解——week1
|
机器学习/深度学习 存储 算法
《剑指offer》题解——week4
《剑指offer》题解——week4
117 0
《剑指offer》题解——week4
|
机器学习/深度学习 存储 算法
《剑指offer》题解——week2
由于需要对结果进行取余,导致`不能使用动态规划`,因为取模导致了dp的运算出现了问题。dp是通过最优子问题来计算出最终结果的,而取模之后就导致计算最优子问题出现了问题,计算出来的`dp[i-j]*j`表面上可能是最大的,但是`dp[i-j]`也是经过取模运算的,从而这会导致`dp[i]`不是由前面的最优子问题推出来的。
75 0
《剑指offer》题解——week2
|
算法 Java 索引
《剑指offer》题解——week6
《剑指offer》题解——week6
58 0
《剑指offer》题解——week6
|
算法 搜索推荐 Java
《剑指offer》题解——week5
《剑指offer》题解——week5
59 0
《剑指offer》题解——week5
LeeCode 57. Insert Interval
给定一组非重叠间隔,在间隔中插入新间隔(必要时合并)。 您可以假设间隔最初是根据其开始时间排序的。
75 0
LeeCode 57. Insert Interval