题目描述:

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. CSS3新的字体尺寸单位rem

    CSS3引入新的字体尺寸单位 rem ,可以简单记忆为root rm. CSS3的出现,他同时引进了一些新的单位,包括我们今天所说的rem.在W3C官网上 是这样描述rem的——“font size ...

  2. [转载]VS2012程序打包部署详解

    上篇博客把收费系统的总体设计进行了一遍讲解,讲解的同时掺杂了些有关.NET编译机制的总结.程序编写测试完成后接下来我们要做的是打包部署程序,但VS2012让人心痛的是没有了打包工具.不知道出于什么原因 ...

  3. PAT-乙级-1022. D进制的A+B (20)

    1022. D进制的A+B (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 输入两个非负10进制整数A和 ...

  4. Nagios的安装配置与应用之五监控远程Linux服务器

    本文出自 “曹坏水” 博客,请务必保留此出处http://cao2012.blog.51cto.com/366908/1132113 NRPE是Nagios的一个功能扩展,它可在远程Linux和UNI ...

  5. 2013 Multi-University Training Contest 4 Who's Aunt Zhang

    看题就知道要用polya,但是当时没做出来,还是不是很熟悉polya!!! 总共有24种置换: 1. 不做任何旋转 K ^ (54 + 12 + 8) 2. 绕相对面中心的轴转 1) 90度 K ^ ...

  6. Android 显示大图片

    主要的代码如下: BitmapFactory.Options options = new BitmapFactory.Options(); //图片解析配置 options.inJustDecodeB ...

  7. android dialog 原来dialog对话框也有自己的按键监听事件 onKeyDown方法

    探讨在一个activity中按menu键时弹出自己定义的dialog(自定义菜单对话框)时,再按一次手机的menu键发现这个自定义的dialog菜单并没有关闭,原来是这个dialog内部也有onKey ...

  8. 实例讲解Nginx下的rewrite规则

    一.正则表达式匹配,其中:* ~ 为区分大小写匹配* ~* 为不区分大小写匹配* !~和!~*分别为区分大小写不匹配及不区分大小写不匹配二.文件及目录匹配,其中:* -f和!-f用来判断是否存在文件* ...

  9. 使用LinkedList实现Stack与Queue

    LinkedList数据结构是一种双向的链式结构,每一个对象除了数据本身外,还有两个引用,分别指向前一个元素和后一个元素. 栈的定义栈(Stack)是限制仅在线性表的一端进行插入和删除运算.(1)通常 ...

  10. R语言学习笔记:因子(Factors)

    因子提供了一个简单并且紧凑的形式来处理分类(名义上的)数据.因子用”水平level”来表示所有可能的取值.如果数据集有取值个数固定的名字变量,因子就特别有用. > g<-c("f ...