题目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)根据日历对象获取改日期是星期 ...
随机推荐
- office安装不了 “windows installer 服务不能更新一个或多个受保护的windows文件”
出现这种情况可能是系统中某些文件缺失了,一般发生于安装GHOST版或做过精简的系统 打开C:\WINDOWS\msagent 看看文件夹中内容是不是如下图所示: 再打开C:\Program Files ...
- 团体程序设计天梯赛-练习集L1-005. 考试座位号
L1-005. 考试座位号 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 每个PAT考生在参加考试时都会被分配两个座位号,一个 ...
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Pokemon Master
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3776 题意:比较两组数据的总和大小. #include <iostr ...
- Android Activity的切换动画
Android的Activity切换有两种方法, 第一种是用代码方式实现: Activity A跳转到Activity B,要在startActivity(intent)后面加上overridePen ...
- 李洪强iOS开发之拓展篇—UIDynamic(简单介绍)
iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能 ...
- Mac中编译安装Qt 4.4
解压下载到的.gz源码:gunzip xxx.tar.gztar xvf xxx.tar, 其实在Mac中可以直接双击解压的.然后定位到解压后的目录下:./configuremakesudo make ...
- SQLite设置主键自动增长及插入语法
SQLite中,一个自增长字段定义为INTEGER PRIMARY KEY AUTOINCREMENT,那么在插入一个新数据时,只需要将这个字段的值指定为NULL,即可由引擎自动设定其值,引擎会设定为 ...
- WPF之小动画三
如果前两篇的博客太为普通,那么接下来的内容将让你动画实在是太厉害了.本文将会介绍两个关于纯手工实现动画的形式,当然动画效果就不用我多说了. 基于帧的动画: 此处的帧并不是之前介绍的Animation这 ...
- 分布式全局不重复ID生成算法
分布式全局不重复ID生成算法 算法全局id唯一id 在分布式系统中经常会使用到生成全局唯一不重复ID的情况.本篇博客介绍生成的一些方法. 常见的一些方式: 1.通过DB做全局自增操作 优点:简单.高 ...
- POJ1182
这题需要注意就是 并查集中 相对位置 注意与绝对距离区别 #include<cstdio> #define maxn 50005 int ans,i,a,b,p,fa,fb,n,k; in ...