牛客网–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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • PCL点云处理算法汇总(C++长期更新版)

    PCL点云处理算法汇总(C++长期更新版)PCL学习目录

    2022年4月29日
    139
  • 使用zabbix监控redis内存使用

    使用zabbix监控redis内存使用本篇提到的监控环境是有条件的,即默认单机只运行一个redis实例,且默认运行的端口是6379(也可以是其他端口,需要通过sed-i’s/6379/你修改的端口/g’xml模板文件修改模板文件里的端口号)。即然有这么多局限,岂不是适应用环境很差。确实,本篇算是一个基础部分,为后面提到的lld(lowleveldiscovery)自动发现做铺垫。由于前面几部分也对基础的东西做了很多总结…

    2022年5月18日
    38
  • phpstorm2021永久激活码-激活码分享

    (phpstorm2021永久激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html9ZHRNTE33T-eyJsaWN…

    2022年3月28日
    851
  • 刷屏专用超长复制_跪求超超长刷屏字符剑。。

    该楼层疑似违规已被系统折叠隐藏此楼查看此楼….飘过…..飘过……飘过…….飘过……..飘过……..飘过……..飘过……..飘过…….飘过……飘过…..飘过….飘过…飘过..飘过.飘过.飘过.飘过..飘过…飘过….飘过…..飘过……飘过…….飘过……..飘过……..飘过….

    2022年4月8日
    94
  • LVM 应用配置详解

    LVM 应用配置详解

    2021年8月5日
    47
  • arm cortex-a57 cpu_处理器a73和a53

    arm cortex-a57 cpu_处理器a73和a53在如今这个电子产品泛滥的年代,仅仅靠品牌或是外观已经不足以辨别产品的优劣,其内置的处理器自然也就成为了分辨产品是否高端的标准之一。那么我们今天就不妨好好了解一下近几年来电子产品中较为主流的RAM处理器。  在这之前让我们先简单认识一下处理器的架构。所谓处理器架构是CPU厂商给属于同一系列的CPU产品定的一个规范,主要目的是为了区分不同类型CPU的重要标示。目前市面上的CPU指令集分类主要分有…

    2022年8月31日
    14

发表回复

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

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