Unix时间戳

题目链接: http://exercise.acmcoder.com/online/online_judge_ques?ques_id=3356&konwledgeId=40

解题思路: 暴力枚举当前的年份,月份,天数。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 typedef long long LL;
 5 const int MAXN=100005;
 6 const LL MON7 = 1e9+7;
 7 int d[][12]={31,28,31,30,31,30,31,31,30,31,30,31,
 8               31,29,31,30,31,30,31,31,30,31,30,31};
 9 
10 LL seconds;
11 LL days;
12 LL year, month, day;
13 
14 bool isLeapYear(LL year)
15 {
16     return (year%400==0 || year%4==0 && year%100!=0);
17 }
18 
19 //LL searchYear(LL days)
20 //{
21 //
22 //}
23 
24 void solve()
25 {
26     days = seconds/24/60/60+1;
27     year=1970;
28     month=0;
29     day=0;
30     bool flags = isLeapYear(year);
31     while (flags && days>366 || days>365)
32     {
33         ++year;
34         days-=(flags?366:365);
35         flags=isLeapYear(year);
36     }
37     while (days>d[flags][month]) days-=d[flags][month++];
38     day=days;
39     printf("%04lld %02lld %02lld\n",year, month+1, day);
40 }
41 
42 int main()
43 {
44 #ifndef ONLINE_JUDGE
45     freopen("test.txt","r",stdin);
46 #endif // ONLINE_JUDGE
47     int Case;
48     //scanf("%d",&Case);
49     while (scanf("%lld", &seconds)!=-1)
50     {
51         solve();
52     }
53     return 0;
54 }

 

posted @ 2018-04-24 23:47  只会一点暴力  阅读(193)  评论(0编辑  收藏  举报