题目描述:

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. 看几道JQuery试题后总结(下篇)

    感谢圆友的提醒 昨天下午完成了9道试题中的前4道,之后好多园友存在些疑惑和建议,在这里我一并说一下吧.首先对于昨天第一题可能存在误导,在JQuery中并没有innerHTML这个属性,不过我们可以将J ...

  2. 2013流行Python项目汇总

    2013流行Python项目汇总 转自:http://www.kankanews.com/ICkengine/archives/102963.shtml Python作为程序员的宠儿,越来越得到人们的 ...

  3. 10 things you should know about NoSQL databases

    For a quarter of a century, the relational database (RDBMS) has been the dominant model for database ...

  4. SpringMVC ResponseBody返回中文乱码解决方案

    @RequestMapping(value = "/getForm") @ResponseBody public List<String> getForm(String ...

  5. Python之函数篇

    函数形参 函数取得的参数是你提供给函数的值,这样函数就可以利用这些值 做 一些事情.这些参数就像变量一样,只不过它们的值是在我们调用函数的时候定义的,而非在函数本身内赋值. 参数在函数定义的圆括号对内 ...

  6. 图模型的统计推断 inference in graphical models(马尔科夫链的推断)

    有关因子图(factor graphs)以及其在sum product 算法,max-algorithm中的应用,将在一下篇博客中分享. 谢谢您的关注,欢迎提出意见问题.

  7. sudo: ./sd_fusing.sh:找不到命令

    1. -----

  8. [转] Android自动化测试之MonkeyRunner录制和回放脚本(四)

    测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py  http://mirror ...

  9. JPA详解

    2006 年 5 月 2 日,EJB 3.0 规范最终版由 JCP(Java Community Process) 正式公布,标准号为 JSR(Java Specification Request)2 ...

  10. JS将下拉框的disable变为able的方法

    在jquery中可以通过jqueryObj.attr("disabled","disabled")将页面中某个元素置为不可编辑或触发状态,但是在jquery的A ...