HDU 4515 推断时间
今年腾讯马拉松初赛第五场的签到题,感觉是几场签到题里面比较有意思的一个。
题意: 当前日前设置为2013年03月24日,输入一个日子数,计算此日子之后之前是哪年哪月哪号
一些公司的笔试面试题喜欢拿这个日期类似的作文章
改变形式:
已知当前的日期,给定一个目标日期,求过了几天,都可以用模拟来做
HDU4515中注意点:
1.数组最好加个前缀,可以直接取第X个月日期
2.判断闰年函数
3.输出格式,%xd表示x位整数
#include <iostream> #include <vector> #include <map> #include <list> #include <set> #include <deque> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <cctype> #include <cstdio> #include <iomanip> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <queue> using namespace std; ///宏定义 const int INF = 1000000000; const int MAXN = 110; const int maxn = MAXN; ///全局变量 和 函数 int days, D; int year, month, day; int Month[2][13] = {0,31,28,31,30,31,30,31,31,30,31,30,31, 0,31,29,31,30,31,30,31,31,30,31,30,31}; int isRun(int y) { if ((y % 400 == 0) || ((y % 4 == 0) && (y % 100 != 0))) return 1; return 0; } int main() { ///变量定义 int N; scanf("%d", &N); while (N--) { scanf("%d", &days); D = days; year = 2013; month = 3; day = 24; while (D--) { int t = isRun(year); day++; if (day > Month[t][month]) { day = 1; month++; if (month > 12) { month = 1; year++; } } } printf("%04d/%02d/%02d", year, month, day); D = days; year = 2013; month = 3; day = 24; while(D--) { int t; day--; if (day <= 0) { month--; if (month <= 0) { year--; month = 12; } t = isRun(year); day = Month[t][month]; } } printf(" %04d/%02d/%02d\n", year, month, day); } ///结束 return 0; }