codeforces B. Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/304/B
题目意思:给出两个日期,需要算出这两个日期之间有多少日。
细心模拟就可以了。特别要注意的是,两个日期是同一年的处理。我的解决方法是,算出小的那一个日期的天数离它所处月份还有多少天,大的日期的天数加上去,还有一部分是它们之间相隔的月数总天数。另外,为了方便处理,保证了第一个处理的日期是较小的。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std; static char dd[][] = {
{, , , , , , , , , , , , },
{, , , , , , , , , , , , }
}; int jd_year(int year)
{
if (year % == && year % != || year % == )
return ;
return ;
} int day_of_year(int year, int month, int day) // 算出该日期在该year年处于第几天
{
for (int i = ; i < month; i++)
day += dd[jd_year(year)][i];
return day;
} int main()
{
int y, m, d, y1, m1, d1, i, cnt;
scanf("%d:%d:%d", &y, &m, &d);
scanf("%d:%d:%d", &y1, &m1, &d1);
if (y > y1 || (y == y1 && m > m1) || (y == y1 && m == m1 && d > d1))
{
swap(y, y1);
swap(m, m1);
swap(d, d1);
}
if (y == y1)
{
if (m != m1)
{
cnt = dd[jd_year(y)][m]-d + d1;
for (i = m+; i < m1; i++)
cnt += dd[jd_year(y)][i];
}
else
cnt = d1 - d;
}
else
{
cnt = day_of_year(y, m, d);
if (jd_year(y))
cnt = - cnt;
else
cnt = - cnt;
cnt += day_of_year(y1, m1, d1);
for (i = y+; i < y1; i++)
{
if (jd_year(i))
cnt += ;
else
cnt += ;
}
}
printf("%d\n", cnt);
return ;
}
codeforces B. Calendar 解题报告的更多相关文章
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces 31C Schedule 解题报告
题目链接:http://codeforces.com/problemset/problem/31/C 题目意思:给出 n 个 lessons 你,每个lesson 有对应的 起始和结束时间.问通过删除 ...
- codeforces 499B.Lecture 解题报告
题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 profes ...
- codeforces 495C. Treasure 解题报告
题目链接:http://codeforces.com/problemset/problem/495/C 题目意思:给出一串只有三种字符( ')','(' 和 '#')组成的字符串,每个位置的这个字符 ...
- codeforces 490B.Queue 解题报告
题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位 ...
- CodeForces 166E -Tetrahedron解题报告
这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedro ...
- codeforces 489A.SwapSort 解题报告
题目链接:http://codeforces.com/problemset/problem/489/A 题目意思:给出一个 n 个无序的序列,问能通过两两交换,需要多少次使得整个序列最终呈现非递减形式 ...
- codeforces 485A.Factory 解题报告
题目链接:http://codeforces.com/problemset/problem/485/A 题目意思:给出 a 和 m,a 表示第一日的details,要求该日结束时要多生产 a mod ...
- codeforces 483A. Counterexample 解题报告
题目链接:http://codeforces.com/problemset/problem/483/A 题目意思:给出一个区间 [l, r],要从中找出a, b, c,需要满足 a, b 互质,b, ...
随机推荐
- Ubuntu 16.04下使用Wine安装文件比对工具Beyond Compare 4
说明: 1.使用的Wine版本是深度出品(Deepin),已经精简了很多没用的配置,使启动能非常快,占用资源小. 2.关于没有.wine文件夹的解决方法:在命令行上运行winecfg: 下载: (链接 ...
- sqlite数据库转换为mysql数据库
SQLite工具我用的SQLiteStudio2.1.5 下载地址 http://sqlitestudio.pl/?act=download SQLiteStudio打开数据库文件,点工具->导 ...
- flask的restful api模块flask_restful和认证模块flask_httpauth
参考: 1.https://zhuanlan.zhihu.com/p/24629177 2.https://github.com/shengulong/LearnPython/blob/master/ ...
- 全方位绕过软WAF攻略
0×00 前言 现在软waf较为多,就在今年夏天苦逼挖洞的日子里经常遇到360主机卫士,安全狗,云锁之类的软waf进行拦截,经常碰到如下拦截提示: 看到以上三个拦截提示就让人头疼不已,欲罢不能. so ...
- vue doubleclick 鼠标双击事件
Vue-dblclick事件(此外事件还有mouseover,mouseout,click,mousdown...): v-on:dblclick="函数" v-on:click/ ...
- 4.php整合Memcached
用法: nginx响应请求时,直接请求memcached, 如果没有相应的内容,再回调PHP页面,去查询database,并写入memcached. 分析: memcached是k/v存储, key- ...
- nodejs REPL(交互式解释器)
Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互式解释器) 表示一个电脑的环境,类似 Window 系统的终端或 Unix/Linux ...
- web前端面试系列 - js中的prototype
js中一切皆为对象,其中函数也是一种对象, 而每个函数都有一个prototype属性,其值也是一个对象. 一.prototype的作用 1. 在多个实例对象之间共享数据和方法. 2. 通过原型链实现继 ...
- Kuebernetes之DaemonSet
系列目录 DaemonSet确保集群中每个(部分)node运行一份pod副本,当node加入集群时创建pod,当node离开集群时回收pod.如果删除DaemonSet,其创建的所有pod也被删除,D ...
- 李洪强iOS开发之 - 项目架构
李洪强iOS开发之 - 项目架构 01 - 在Appdelegate中设置跟控制器 //导入头文件