题目链接: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. 小程序使用wxParse插件解析html标签图片间距问题

    转自:https://www.cnblogs.com/likun123/p/9543376.html 小程序解析html标签,就需要用到wxParse啦.但是在解析连续图片的时候,会发现图片之间会有间 ...

  2. Java中HashMap的初始容量设置

    根据阿里巴巴Java开发手册上建议HashMap初始化时设置已知的大小,如果不超过16个,那么设置成默认大小16: 集合初始化时, 指定集合初始值大小. 说明: HashMap使用HashMap(in ...

  3. JavaEETest

    原文:https://github.com/lenve/JavaEETest

  4. Java中char转为16进制

    Java中char转为16进制 char a = '0'; String hexStr = Integer.toHexString(a); System.out.println(hexStr);

  5. 从头写一个Cucumber测试(一) Selenium Test

    转载:https://yaowenjie.github.io/%E7%BC%96%E7%A8%8B%E7%9B%B8%E5%85%B3/cucumber-test, 背景(废话不读系列)   前段时间 ...

  6. Eclipse 教程

    Eclipse 教程 Eclipse 是一个开放源代码的.基于 Java 的可扩展开发平台. Eclipse 是 Java 的集成开发环境(IDE),当然 Eclipse 也可以作为其他开发语言的集成 ...

  7. javascript一些面试经常使用的问题总结

    有关函数调用变量问题 var a =10; function aaa(){ alert(a); } function bbb(){ var a = 20; aaa(); //10 } bbb(); 变 ...

  8. vue2.0 自定义 侧滑删除(LeftSlider)组件

    1.自定义侧滑删除组件 LeftSlider.vue <!-- 侧滑删除 组件 --> <template> <div class="delete"& ...

  9. pwm驱动原理和代码实现

    学这个pwm真是非常曲则,首先是看s3c2440的datasheet,全英文的,并且还有硬件的时序图(非常多是硬件的工作原理,和软件控制不相关). 看了非常久加上网上看了资料才把这个pwm弄通. 当然 ...

  10. hdu 1548

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...