【日期问题】九度OJ 1043:Day of week

2024-03-08 21:38
文章标签 问题 day 日期 oj 1043 week 九度

本文主要是介绍【日期问题】九度OJ 1043: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.

样例输入:

9 October 2001 
14 October 2001

样例输出:

Tuesday
Sunday

提示:

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

二、代码及注释

#include<stdio.h>
#include<string.h>
#define ISYEAP(x) ((x%100!=0 && x%4==0) || x%400==0) ?1:0
using namespace std;
//思想:设定一个源点时间(如0000年1月1日),计算将两个日期的日期距离源点日期的时间差,存入数组中,接着计算差值即可(必要时加绝对值)
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
};
struct Date{int Year;int Month;int Day;void nextDay(){Day++;if(Day>dayofMonth[Month][ISYEAP(Year)]){Day=1;Month++;if(Month>12){Month=1;Year++;}}}
};
int buf[5001][13][32];
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 main(){Date tmp;int cnt=0;//统计该日期到0000年1月1日的天数tmp.Year=0;tmp.Month=1;tmp.Day=1;while(tmp.Year!=5001){buf[tmp.Year][tmp.Month][tmp.Day]=cnt;tmp.nextDay();cnt++;}int y,m,d;char s[20];//输入的月名while(scanf("%d%s%d",&d,&s,&y)!=EOF){for(m=1;m<=12;m++){if(strcmp(s,monthName[m])==0){//进行字符串比较break;}}int days=buf[y][m][d]-buf[2012][7][16];//已知2012年7月16日为星期一days+=1;//星期一,所以days+1,星期几就加几printf("%s\n",weekName[(days%7+7)%7]);}
}

这篇关于【日期问题】九度OJ 1043:Day of week的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/788481

相关文章

Spring Boot中JSON数值溢出问题从报错到优雅解决办法

《SpringBoot中JSON数值溢出问题从报错到优雅解决办法》:本文主要介绍SpringBoot中JSON数值溢出问题从报错到优雅的解决办法,通过修改字段类型为Long、添加全局异常处理和... 目录一、问题背景:为什么我的接口突然报错了?二、为什么会发生这个错误?1. Java 数据类型的“容量”限制

关于MongoDB图片URL存储异常问题以及解决

《关于MongoDB图片URL存储异常问题以及解决》:本文主要介绍关于MongoDB图片URL存储异常问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录MongoDB图片URL存储异常问题项目场景问题描述原因分析解决方案预防措施js总结MongoDB图

SpringBoot项目中报错The field screenShot exceeds its maximum permitted size of 1048576 bytes.的问题及解决

《SpringBoot项目中报错ThefieldscreenShotexceedsitsmaximumpermittedsizeof1048576bytes.的问题及解决》这篇文章... 目录项目场景问题描述原因分析解决方案总结项目场景javascript提示:项目相关背景:项目场景:基于Spring

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基

usb接口驱动异常问题常用解决方案

《usb接口驱动异常问题常用解决方案》当遇到USB接口驱动异常时,可以通过多种方法来解决,其中主要就包括重装USB控制器、禁用USB选择性暂停设置、更新或安装新的主板驱动等... usb接口驱动异常怎么办,USB接口驱动异常是常见问题,通常由驱动损坏、系统更新冲突、硬件故障或电源管理设置导致。以下是常用解决

Mysql如何解决死锁问题

《Mysql如何解决死锁问题》:本文主要介绍Mysql如何解决死锁问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录【一】mysql中锁分类和加锁情况【1】按锁的粒度分类全局锁表级锁行级锁【2】按锁的模式分类【二】加锁方式的影响因素【三】Mysql的死锁情况【1

Java实现优雅日期处理的方案详解

《Java实现优雅日期处理的方案详解》在我们的日常工作中,需要经常处理各种格式,各种类似的的日期或者时间,下面我们就来看看如何使用java处理这样的日期问题吧,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言一、日期的坑1.1 日期格式化陷阱1.2 时区转换二、优雅方案的进阶之路2.1 线程安全重构2

SpringBoot内嵌Tomcat临时目录问题及解决

《SpringBoot内嵌Tomcat临时目录问题及解决》:本文主要介绍SpringBoot内嵌Tomcat临时目录问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录SprinjavascriptgBoot内嵌Tomcat临时目录问题1.背景2.方案3.代码中配置t

SpringBoot使用GZIP压缩反回数据问题

《SpringBoot使用GZIP压缩反回数据问题》:本文主要介绍SpringBoot使用GZIP压缩反回数据问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot使用GZIP压缩反回数据1、初识gzip2、gzip是什么,可以干什么?3、Spr

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32