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


相关推荐

  • maven安装及配置(详细版)

    maven安装及配置(详细版)1.下载:方式一可以从官方下载,下载页面:http://maven.apache.org/download.cgi方式二:或者题主提供的版本下载maven安装包提取码:ysns下载好后是一个压缩文件2.安装:maven压缩包解压到一个没有中文,空格或其他特殊字符的文件夹内即可使用。3.配置MAVEN_HOMEmaven的使用是在jdk的基础上,所以电脑必须有jdk第一步:新增环境变量:MAVEN_HOME第二步:在path环境变量中添加:%MAVEN_HOME%\bin

    2022年5月28日
    40
  • synchronized偏向锁和轻量级锁_java轻量级锁,偏向锁,重量级锁

    synchronized偏向锁和轻量级锁_java轻量级锁,偏向锁,重量级锁今天简单了解了一下java轻量级锁和重量级锁以及偏向锁。看了看这篇文章觉得写的不错原文链接java 偏向锁、轻量级锁及重量级锁synchronized原理Java对象头与Monitorjava对象头是实现synchronized的锁对象的基础,synchronized使用的锁对象是存储在Java对象头里的。对象头包含两部分:Mark Word 和 Class Metadata Address其中Mark Word在默认情况下存储着对象的HashCode、分代年龄、锁标记位等以下是32位JVM的

    2022年8月8日
    4
  • JAVA中的数组插入与删除指定元素

    JAVA中的数组插入与删除指定元素今天学了Java的数组,写了数组的插入和删除,本人小白,写给不会的小白看,大神请忽略,有错请大家指出来;/**给数组指定位置数组的插入*/importjava.util.*;publicclassArrayInsert{publicstaticvoidmain(String[]args){System.out.println(“请用键

    2022年6月26日
    59
  • netty权威指南(第二版)对应的源码「建议收藏」

    netty权威指南(第二版)对应的源码「建议收藏」《netty权威指南(第二版)对应的源码》一个哥们创建的git库《源码原始地址》有关该书的更多信息可以关注李林峰老师的在ifeve网站上的文章:http://ifeve.com/author/linfeng/

    2022年10月2日
    2
  • 计算机语言有哪些_计算机英语第五版刘艺pdf

    计算机语言有哪些_计算机英语第五版刘艺pdf计算机程序设计艺术 第3卷 排序和查找(英文影印版.第2版)

    2022年4月21日
    105
  • 初步swift语言学习笔记8(保留了很多OC实现)

    初步swift语言学习笔记8(保留了很多OC实现)

    2022年1月10日
    35

发表回复

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

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