zoukankan      html  css  js  c++  java
  • 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
    ",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 }
  • 相关阅读:
    HTML5响应式导航
    草原图片大全
    草原psd素材
    仿堆糖图片自滚动瀑布流效果
    夏日户外风景PSD素材
    国画经典之梅花PSD素材
    更改VS的运行主窗体
    在VS中如何更换项目名称
    如何使用Visual Studio 2008(VS2008)编译C语言
    #region 私有字段
  • 原文地址:https://www.cnblogs.com/djingjing/p/8934537.html
Copyright © 2011-2022 走看看