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, ...
随机推荐
- HDU5618 Jam's problem again
CDQ分治模板题 #include<cstdio> #include<cctype> #include<algorithm> #include<cstring ...
- IntelliJ IDEA导入包的顺序调整和按包类型分类(保持和Eclipse一致)
调整的内容如下: 空行 import java.* 空行 import javax.* 空行 import com.* 空行 import all other imports 空行 import st ...
- Unity -- 入门教程三
进入这个页面,按编译器版本进行下载,我用的是2010,所以要下载这个. 安装就不用我教了,下面开始看我是如何导入Unity VS的. 点击Import之后我们会发现并没有发生什么,但是接下来我们按一下 ...
- iOS -- SKTexture类
SKTexture类 继承自 NSObject 符合 NSCodingNSCopyingNSObject(NSObject) 框架 /System/Library/Frameworks/Sprite ...
- python得到最长递增子串长度及起始位置【转】
def incSeq(seq): start = 0 for i in xrange(1, len(seq)): if seq[i] < seq[i-1]: yield start, i - s ...
- Android自己定义实现循环滚轮控件WheelView
首先呈上效果图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- Odoo超售订单
当 交付给客户的货物多于订购的数量时,就形成'超售'状态: 对于超售的部分,需要进行开票处理,以及根据情况修改交货 发生超售的前提是,产品开票策略为 '按订购数量开票' 同时需要 允许 ...
- [ssh新闻公布系统三]存储新闻
一.存储新闻dao方法 在NewsDao.java中新增存储新闻的saveOrupdate方法 public void saveOrupdate(News news){ getSession().sa ...
- Solaris服务管理
远程登录协议 telnet \ssh 等.当然我们可以查看谁登录过我的系统,以及可以利用ftp记录日志. 一.SMF: 服务管理工具 优点:自动恢复意外终止的服务,支持服务的依赖关系,一个服务可以有多 ...
- Spring集成JDBC
不同spring版本合成的方式,有时候不一样,需要查看帮助文档来看如何集成,帮助文档在spring发行包中. 1.导入spring的包(这里吧Spring-3.1.3 Release的所有jar包都导 ...