Sicily 1814. 日期计算问题
来源:互联网 发布:收银软件免费版 编辑:程序博客网 时间:2024/06/05 21:51
还是写类
时间分三部分. 大年过了多少天, 小年还剩多少天, 中间多少天.
// Problem#: 1814// Author#: Reid Chan#include <iostream>#include <string>using namespace std;int months[13] = { 29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };class time_y {private: int change_to_int(string t) { int len = t.length(); int sum = 0; int tmp = 1; for (int i = len - 1; i >= 0; i--) { sum += tmp * (t[i] - '0'); tmp *= 10; } return sum; }public: int year; int month; int day; time_y(string time) { year = change_to_int(time.substr(0, 4)); month = change_to_int(time.substr(5, 2)); day = change_to_int(time.substr(8, 2)); }};bool isY(int y) { if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) { return true; } return false;}int cal_day(time_y t, bool pre) { int day = 0; int end = t.month; for (int i = 1; i < end; ++i) { if (i == 2 && isY(t.year)) { day += months[0]; continue; } day += months[i]; } day += t.day; if (pre) { return isY(t.year) ? 366 - day : 365 - day; } else { return day; }}int cal_year(int bgn, int end) { int day = 0; for (int i = bgn + 1; i < end; ++i) { if (isY(i)) { day += 366; } else { day += 365; } } return day;}int main() { int t; cin >> t; while(t--) { string a, b; cin >> a >> b; time_y t1(a), t2(b); int result = 0; if (t1.year > t2.year) { result += cal_day(t2, true); result += cal_day(t1, false); result += cal_year(t2.year, t1.year); } else if (t1.year < t2.year) { result += cal_day(t1, true); result += cal_day(t2, false); result += cal_year(t1.year, t2.year); } else { int r1 = cal_day(t1, false); int r2 = cal_day(t2, false); result = (r1 - r2 > 0) ? r1 - r2 : r2 - r1; } cout << result << endl; } return 0;}
0 0
- sicily--1814. 日期计算问题
- sicily 1814.日期计算问题
- Sicily 1814. 日期计算问题
- Sicily 1814. 日期计算问题
- Sicily 1814日期计算问题
- 1000 日期计算问题
- 日期计算的问题
- 关于日期计算的问题
- 关于日期计算的问题
- java的日期计算问题
- Java日期计算溢出问题
- sicily 后缀表达式计算
- NSDate的计算问题、日期计算、时区问题、NSTimer
- NSDate的计算问题,日期计算,时区问题,NSTimer
- NSDate的计算问题,日期计算,时区问题,NSTimer
- NSDate的计算问题、日期计算、时区问题、NSTimer
- asp中计算日期差的问题
- Java中计算日期的问题
- unity3d 不同平台载入XML文件的方法——IOS MAC Android
- Makefile基础
- linux内核IP地址转换函数
- Makefile
- C语言编程(练习1:字符串和字符串函数)
- Sicily 1814. 日期计算问题
- linux下nginx+python+fastcgi部署总结(web.py版)
- contiki 源码分析之网络层(三)(core / net)
- java设计模式-策略模式
- Javascript——百度地图API——显示位置
- Sicily 1052. Candy Sharing Game
- linux下nginx+python+fastcgi部署总结(django版)
- requestAnimationFrame绘制图像
- 【ci框架】PHP常见面试题汇总。。。