题目1043:Day of Week(输入日期与当前日起天数差%7,在做相关星期调整)
题目描述:
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<iostream>
using namespace std; # include<string.h> int main()
{
char month[][] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
char week[][] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
int dOFm[] = { , , , , , , , , , , , , };
int y, m, d;
int cy = , cm = , cd = , cw = ;//这个要更换成今天的具体情况
char mon[];
int i, count1, count2, dOFweek; while (cin >> d >> mon >> y)
{
for (i = ; i <= ; i++)
{
if (strcmp(month[i], mon) == )
{
m = i;
break;
}
}
//cout << m << endl; if (y > cy || (y == cy&&m > cm) || (y == cy&&m == cm&&d > cd))//输入的年月日在今天之后
{
//计算cy cm cd离cy 01 01的天数
count1 = ;
for (i = ; i < cm; i++)
{
count1 += dOFm[i];
}
if (cm> && ((cy % == && cy % != ) || cy % == ))
{
count1 += ;
}
count1 += cd; //计算y m d离cy 01 01的天数
count2 = ;
for (i = cy; i < y; i++)
{
if ((i % == && i % != ) || i % == )
{
count2 += ;
}
else
{
count2 += ;
}
}
for (i = ; i < m; i++)
{
count2 += dOFm[i];
}
if (m> && ((y % == && y % != ) || y % == ))
{
count2 += ;
}
count2 += d; //cout << count2 - count1 << endl;
dOFweek = ((count2 - count1) % + cw) % ;
cout << week[dOFweek] << endl;
}
else//输入的年月日在今天之前
{
//计算y m d离y 01 01的天数
count1 = ;
for (i = ; i < m; i++)
{
count1 += dOFm[i];
}
if (m> && ((y % == && y % != ) || y % == ))
{
count1 += ;
}
count1 += d; //计算cy cm cd离y 01 01的天数
count2 = ;
for (i = y; i < cy; i++)
{
if ((i % == && i % != ) || i % == )
{
count2 += ;
}
else
{
count2 += ;
}
}
for (i = ; i < cm; i++)
{
count2 += dOFm[i];
}
if (cm> && ((cy % == && cy % != ) || cy % == ))
{
count2 += ;
}
count2 += cd; //cout << count2 - count1 << endl;
dOFweek = ((cw - (count2 - count1) % ) + ) % ;
cout << week[dOFweek] << endl;
}
}
return ;
}
/**************************************************************
Problem: 1043
User: mmcNuaa@163.com
Language: C++
Result: Accepted
Time:0 ms
Memory:1520 kb
****************************************************************/
题目1043:Day of Week(输入日期与当前日起天数差%7,在做相关星期调整)的更多相关文章
- Python中判断是否为闰年,求输入日期是该年第几天
#coding = utf-8 def getLastDay(): y = int(input("Please input year :")) m = int(input(&quo ...
- js快捷输入日期
点击这里查看效果http://keleyi.com/keleyi/phtml/jstexiao/10.htm 以下式代码: <!DOCTYPE html> <html> < ...
- php转化输入日期为Unix 纪元到当前时间的秒数 日期筛选
多条件筛选时 日期筛选 部分 demo http://pan.baidu.com/s/1hqGF5Ik 时间输入控件http://www.jq22.com/jquery-info332 输入控件 ...
- Javascript Date 判断输入日期是否正确
JavaScript的Date对象有容错性,可将随意给定的日期的年月日自动生成正确的日期时间 //JavaScript中Date对象容错性 function dateCheck(){ var date ...
- C#字符串截取、获取当前电脑时间、判断输入日期对错 随手记
字符串截取:这个就当复习了,看意见就可以 //身份证生日截取 //Console.WriteLine("请输入18位身份证号:"); //string x = Console.Re ...
- JAVA编写简单的日历,输入日期即可查看日历
利用LocalDate输入年月日找出当月日历 直接上代码 import java.time.LocalDate; import java.util.Scanner; public class Cale ...
- Python练习笔记——计算输入日期为改年的第几天、星期几
# 输入年月日,如:1995年12月10日,计算是该年的第几天?# 同时计算出当天是星期几? print("请依据提示依次输入您想查询的年 月 日") # 第一段代码块(年月日输入 ...
- python判断输入日期是该年的第几天
1.输入日期,判断日期是该年度的第几天 iyear = int(input("请输入年:\n")) imonth = int(input("请输入月:\n")) ...
- Day_10【常用API】扩展案例2_获取输入日期是哪一年的哪一天的星期几
分析以下需求,并用代码实现 1)已知日期字符串:"2015-10-20",将改日期字符串转换为日期对象 2)将(1)中的日期对象转换为日历类的对象 3)根据日历对象获取改日期是星期 ...
随机推荐
- CSS+DIV:父DIV相对定位+子DIV绝对定位
如何在一个div内将一个div进行绝对定位呢?很简单,把父div的position属性设为relative,子div的position属性设为absolute就可以了... 示例: <html& ...
- 【高斯消元】BZOJ 1770: [Usaco2009 Nov]lights 燈
Description 貝希和她的閨密們在她們的牛棚中玩遊戲.但是天不從人願,突然,牛棚的電源跳閘了,所有的燈都被關閉了.貝希是一個很膽小的女生,在伸手不見拇指的無盡的黑暗中,她感到驚恐,痛苦與絕望. ...
- js中批量处理样式——cssText的使用
http://www.cnblogs.com/snandy/archive/2011/03/12/1980444.html
- mysql数据库备份执行计划
为什么需要数据备份?如果数据库因为人为或其他不可控的因素导致数据库数据丢失或损坏,导致的后果将会非常严重. 为什么需要执行计划?备份操作如果每天人工管理的话,将会非常麻烦,需要借助工具来制定执行计划, ...
- pthread_create()之前的属性设置
一.pthread_create()之前的属性设置1.线程属性设置我们用pthread_create函数创建一个线程,在这个线程中,我们使用默认参数,即将该函数的第二个参数设为NULL.的确,对大多数 ...
- 深入浅出ShellExecute
Q: 如何打开一个应用程序? ShellExecute(this->m_hWnd,"open","calc.exe",""," ...
- 学习记录:浏览器JAVASCRIPT里的WINDOWS,DOCUMNET
看完以下这段话之后,就理解DOCUMNET.READY之类的说法了. 或是JAVASCRIPT的浏览器里更细致的操作DOCUMENT的东西了. DOCUMNET和WINDOWS谁大谁小, 立即执行的匿 ...
- 深入理解ClassLoader(四)—类的父委托加载机制
上几次我们介绍到了JVM内部的几个类加载器,我们来重新画一下这个图,再来看一下他们之间的关系.
- 轻量级Java_EE企业应用实战-第5章Hibernate的基本用法-001
1. package org.crazyit.app.domain; import javax.persistence.*; /** * Description: <br/> * ��վ: ...
- 函数可重入问题reentrant functions(函数执行过程中可以被中断,允许多个副本)
最近经常听到这个名词,以前也听到过,不过接触更多的是“线程安全问题”,而且本人也一直理解的是两个名字的含义是一样的.今天仔细总结一下这个名词相关的概念. 引用博文:可重入函数和不可重入函数 (http ...