题目链接: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 解题报告的更多相关文章

  1. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  2. codeforces 31C Schedule 解题报告

    题目链接:http://codeforces.com/problemset/problem/31/C 题目意思:给出 n 个 lessons 你,每个lesson 有对应的 起始和结束时间.问通过删除 ...

  3. codeforces 499B.Lecture 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 profes ...

  4. codeforces 495C. Treasure 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/C 题目意思:给出一串只有三种字符( ')','(' 和 '#')组成的字符串,每个位置的这个字符 ...

  5. codeforces 490B.Queue 解题报告

    题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位 ...

  6. CodeForces 166E -Tetrahedron解题报告

    这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedro ...

  7. codeforces 489A.SwapSort 解题报告

    题目链接:http://codeforces.com/problemset/problem/489/A 题目意思:给出一个 n 个无序的序列,问能通过两两交换,需要多少次使得整个序列最终呈现非递减形式 ...

  8. codeforces 485A.Factory 解题报告

    题目链接:http://codeforces.com/problemset/problem/485/A 题目意思:给出 a 和 m,a 表示第一日的details,要求该日结束时要多生产 a mod ...

  9. codeforces 483A. Counterexample 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/A 题目意思:给出一个区间 [l, r],要从中找出a, b, c,需要满足 a, b 互质,b, ...

随机推荐

  1. Java中Javadoc的{@link}与@see的简单区别

    {@link}与@see这两个Javadoc注解都可以直接链接类和方法.用法基本一致. 但是@see必须顶头写,而{@link可以任意地方},如下所示: 参考: http://blog.csdn.ne ...

  2. 100 Most Influential Books According to Stack Overflow

    Please read this blog post to see why this is here. This data was created on 02/13/2012 20:00:00 All ...

  3. 3.【nuxt起步】-下面以一个SPA单页程序为例子

    spa:single page applcation 1.components目录新建header.vue,footer.vue Header.vue Footer.vue Pages/index.v ...

  4. Qt中QVector与QList的应用

    首先來看看QVector 的基本使用方式,建立一個可容納兩個元素的QVector ,並使用索引方式存取元素值:QVector<double> vect(2); vect[0] = 1.0; ...

  5. Direct2D教程(一)Direct2D已经来了,谁是GDI的终结者?

    什么是Direct2D 一言以蔽之,就是Windows 7平台上的一个2D图形API,可以提供高性能,高质量的2D渲染.大多数人对Direct2D可能都比较陌生,以至于我之前在论坛上提到这个词的时候, ...

  6. Objective C block背后的黑魔法

    前言 block在Objective C开发中应用非常广泛,我们知道block会捕获外部对象,也知道使用block要防止循环引用. "知其然而不知其所以然"是一件非常痛苦的事情,那 ...

  7. odoo 有哪些文档资源

    // openbook [覆盖 openerp 7 及之前版本] https://doc.odoo.com/     // 最新的 odoo documentation user[覆盖 odoo 9] ...

  8. mysql用户修改登录密码及授予用户远程登录权限

    一.修改用户登录密码: mysql> show databases;ERROR 1820 (HY000): You must SET PASSWORD before executing this ...

  9. bzoj1458 士兵占据

    1458: 士兵占据 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 685  Solved: 398 [Submit][Status][id=1458 ...

  10. Coder-Strike 2014 - Round 2

    t题目链接:Coder-Strike 2014 - Round 2 A题:简单水题,注意能加入反复的数字.因此仅仅要推断是否能把Min和Max加入好.就能够了 B题:开一个sum计算每一个聊天总和,和 ...