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, ...
随机推荐
- Spring实战Day3
通过XML创建装配bean 1.装配不存在成员变量的bean <bean id="talent" class="cn.jqzhong.Spring.study.da ...
- iOS真机测试,为Provisioning添加设备
------------添加设备到provisioning------------- 1,登陆https://developer.apple.com/devcenter/ios/index.actio ...
- 【IntelliJ idea/My/ecplise】启动项目前,修改配置JVM参数
My/ecplise下都是一样的: IDEA下:
- 【转载】Linux下套接字学习
感觉这个系列还不错,学习一下. 先看的是第三篇: http://blog.csdn.net/gatieme/article/details/46334337 < Linux下套接字详解(三)-- ...
- 淘宝HSF 框架使用 总结
@(JAVA开发) 淘宝HSF 框架使用 总结 随着网站访问量增加,仅仅靠增加机器已不能满足系统的要求,于是需要对应用系统进行垂直拆分和水平拆分.在拆分之后,各个被拆分的模块如何通信?如何保证性能?如 ...
- [LeetCode][Java] Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...
- redis 在我做的容器中的配置路劲
配置 /etc/redis/redis.conf 数据库位置 /var/lib/redis/dump.rdb
- LINUX下目标文件的BSS段、数据段、代码段
http://blog.chinaunix.net/uid-27018250-id-3867588.html bss 未初始化的全局数据 data 已经初始化的全局数据 text 代码段,机器指令 r ...
- python 中的电子邮箱的操作
通过python 的代码实现对email的操作,包括发送邮件和读取邮件. import poplib import smtplib from email.header import decode_he ...
- selector的button选中处理问题
1.背景介绍 在做Android项目开发的时候,有时我们须要对button做一些特殊的处理,比方button点击的时候会有一个动画的效果,实际上就是几张图片在短时间的切换.再比方有时候我们须要对界面的 ...