【日期问题】九度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

相关文章

解决pandas无法读取csv文件数据的问题

《解决pandas无法读取csv文件数据的问题》本文讲述作者用Pandas读取CSV文件时因参数设置不当导致数据错位,通过调整delimiter和on_bad_lines参数最终解决问题,并强调正确参... 目录一、前言二、问题复现1. 问题2. 通过 on_bad_lines=‘warn’ 跳过异常数据3

解决RocketMQ的幂等性问题

《解决RocketMQ的幂等性问题》重复消费因调用链路长、消息发送超时或消费者故障导致,通过生产者消息查询、Redis缓存及消费者唯一主键可以确保幂等性,避免重复处理,本文主要介绍了解决RocketM... 目录造成重复消费的原因解决方法生产者端消费者端代码实现造成重复消费的原因当系统的调用链路比较长的时

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499

kkFileView启动报错:报错2003端口占用的问题及解决

《kkFileView启动报错:报错2003端口占用的问题及解决》kkFileView启动报错因office组件2003端口未关闭,解决:查杀占用端口的进程,终止Java进程,使用shutdown.s... 目录原因解决总结kkFileViewjavascript启动报错启动office组件失败,请检查of

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原