题目描述:

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,在做相关星期调整)的更多相关文章

  1. Python中判断是否为闰年,求输入日期是该年第几天

    #coding = utf-8 def getLastDay(): y = int(input("Please input year :")) m = int(input(&quo ...

  2. js快捷输入日期

    点击这里查看效果http://keleyi.com/keleyi/phtml/jstexiao/10.htm 以下式代码: <!DOCTYPE html> <html> < ...

  3. php转化输入日期为Unix 纪元到当前时间的秒数 日期筛选

    多条件筛选时 日期筛选 部分 demo   http://pan.baidu.com/s/1hqGF5Ik 时间输入控件http://www.jq22.com/jquery-info332 输入控件 ...

  4. Javascript Date 判断输入日期是否正确

    JavaScript的Date对象有容错性,可将随意给定的日期的年月日自动生成正确的日期时间 //JavaScript中Date对象容错性 function dateCheck(){ var date ...

  5. C#字符串截取、获取当前电脑时间、判断输入日期对错 随手记

    字符串截取:这个就当复习了,看意见就可以 //身份证生日截取 //Console.WriteLine("请输入18位身份证号:"); //string x = Console.Re ...

  6. JAVA编写简单的日历,输入日期即可查看日历

    利用LocalDate输入年月日找出当月日历 直接上代码 import java.time.LocalDate; import java.util.Scanner; public class Cale ...

  7. Python练习笔记——计算输入日期为改年的第几天、星期几

    # 输入年月日,如:1995年12月10日,计算是该年的第几天?# 同时计算出当天是星期几? print("请依据提示依次输入您想查询的年 月 日") # 第一段代码块(年月日输入 ...

  8. python判断输入日期是该年的第几天

    1.输入日期,判断日期是该年度的第几天 iyear = int(input("请输入年:\n")) imonth = int(input("请输入月:\n")) ...

  9. Day_10【常用API】扩展案例2_获取输入日期是哪一年的哪一天的星期几

    分析以下需求,并用代码实现 1)已知日期字符串:"2015-10-20",将改日期字符串转换为日期对象 2)将(1)中的日期对象转换为日历类的对象 3)根据日历对象获取改日期是星期 ...

随机推荐

  1. js中批量处理样式——cssText的使用

    http://www.cnblogs.com/snandy/archive/2011/03/12/1980444.html

  2. Linux bash shell脚本语法入门

    1.基础 #!/bin/bash   //bash脚本第一句都是这个,他会让系统指定以bash来解释这个脚本 #                 //shell脚本注释符号 2.变量和使用 HOME= ...

  3. nagios plugins之 check_http

    nagios下的check_http ZT具体参数是一个比较重要的点,我带大家来看看.. //显示版本 #./check_http -V check_http v2053 (nagios-plugin ...

  4. Unix/Linux下如何使用Vi编辑器

    vi 的工作模式 Vi 在初始启动后首先进入编辑模式,这时用户可以利用一些预先定义的按键来移动光标.删除文字. 复制或粘贴文字等.这些按键均是普通的字符,例如 l 是向右移动光标,相当于向右箭头键,k ...

  5. Nginx-location配置指南

    语法规则: location [=|~|~*|^~] /uri/ { … } = 开头表示精确匹配 ^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可.nginx不对url做编码,因 ...

  6. Centos后台运行jar

    jar后台运行 nohup java -jar xx.jar >/dev/null & 此处的">/dev/null"作用是将终端输出信息输出到空洞中,即不保存 ...

  7. linux中应用程序main函数中没有开辟进程的,它应该在那个进程中运行呢?

    1.main函数是一个进程还是一个线程? 不知道你是用c创建的,还是用java创建的. 因为它们都是以main()做为入口开始运行的. 是一个线程,同时还是一个进程. 在现在的操作系统中,都是多线程的 ...

  8. 锋利的JQuery-Jquery中的事件和动画

    有时候觉得这些内容都好简单,真想看看就算了. 事件绑定 bing(type [,data],fn) 第一个参数:事件类型包括:blur,focus,load,resize,scroll,unload, ...

  9. C#反射机制介绍

    反射的定义:审查元数据并收集关于它的类型信息的能力.元数据(编译以后的最基本数据单元)就是一大堆的表,当编译程序集或者模块时,编译器会创建一个类定义表,一个字段定义表,和一个方法定义表等.       ...

  10. 树莓派raspbian安装配置(基本配置+中文配置+远程桌面+lighttpd+php+mysql)

    raspbian为树莓派的官方系统,基于Debian裁剪过的Linux系统 其配置过程如下 烧录镜像 首先从树莓派的官方网站上下载镜像和镜像工具 http://www.raspberrypi.org/ ...