牛客网–day of week

牛客网–day of week

题目描述
We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400. For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap. Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.
输入描述:
There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.
输出描述:
Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.

Month and Week name in Input/Output:
January, February, March, April, May, June, July, August, September, October, November, December
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
示例1
输入

9 October 2001
14 October 2001

输出

Tuesday
Sunday

//注意二维字符数组的初始化。
//隐藏条件就是1年1月1日是星期一,把这个时间点设为锚点

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

char  mon[13][20]={" ","January","February","March","April","May","June","July","August","September","October","November","December"};
char  week[7][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool leap(int y){
    if(y%400==0||y%4==0&&y%100!=0) return true;
    else return false;
}
int days(int y,int m,int d){
    int sum=0;
    for(int i=1;i<y;i++){
        if(leap(i)) sum+=366;
        else sum+=365;
    }
    if(leap(y)) day[2]+=1;
    for(int j=1;j<m;j++){
        sum+=day[j];
    }
    sum+=d;
    return sum;
}

int main(){
    int y,m,d;
    char month[13];
    
    while(cin>>d>>month>>y){
        for(int i=1;i<13;i++){
            if(strcmp(month,mon[i])==0){
                m=i;
                break;
            }
        }
        int cnt1=days(y,m,d);
   
        cout<<week[cnt1%7];
    }
    return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/100205.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 012路规律怎么看_五星012路的判断

    012路规律怎么看_五星012路的判断堆题目链接将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种:x is the root:x是根结点;x and y are siblings:x和y是兄弟结点;x is the parent of y:x是y的父结点;x is a child of y:x是y的一个子结点。输入格式:每组测试第1行包含2个正整数N(≤ 1000)和M(≤ 20),分别是插入元素的个数、以及需要判断的命题数。下一行给出区间[−10000,10000]内的N个要被

    2022年8月9日
    5
  • 《FFmpeg从入门到精通》读书笔记(五)

    《FFmpeg从入门到精通》读书笔记(五)写在前面2019.06.24第六章FFmpeg滤镜使用(至6.5结束)FFmpeg滤镜使用FFmpeg滤镜Filter描述格式参数排列方式[输入流或标记名]滤镜参数[临时标记名];[输入流或标记名]滤镜参数[临时标记名]…例如:输入两个文件,一个视频文件input1.mp4,一个图片logo.jpg,将图像流缩放为2000×2000分辨率,放置在视频的左上…

    2022年6月26日
    26
  • Django(9)url指定默认参数「建议收藏」

    Django(9)url指定默认参数「建议收藏」前言当我们访问网页的时候,后台返回列表中有n条数据,此时我们会使用分页,比如一页只展示10条,但是我们访问第一页的时候大多数情况下,都会给url一个默认值,访问的时候直接展示第一页数据案例我们的

    2022年8月7日
    5
  • C++实现远程桌面集群软件[通俗易懂]

    C++实现远程桌面集群软件[通俗易懂]由于在学校需要管理很多主机的需要,自己动手写了个3389桌面集群的软件。软件很简单,分别用2种方式实现:(1)快速登入模式:微软的MsRdpClientActiveX控件实现(2)远程桌面模式:生成.rdp文件实现

    2022年10月15日
    2
  • Idea激活码最新教程2022.3.3版本,永久有效激活码,亲测可用,记得收藏

    Idea激活码最新教程2022.3.3版本,永久有效激活码,亲测可用,记得收藏Idea 激活码教程永久有效 2022 3 3 激活码教程 Windows 版永久激活 持续更新 Idea 激活码 2022 3 3 成功激活

    2025年5月26日
    6
  • HDU1160(LIS)

    HDU1160(LIS)

    2022年1月9日
    42

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号