zoukankan      html  css  js  c++  java
  • 【ACM】poj_2080_Calendar_201307311043


    Calendar
    Time Limit: 1000MS  Memory Limit: 30000K
    Total Submissions: 9787  Accepted: 3677

    Description

    A calendar is a system for measuring time, from hours and minutes, to months and days, and finally to years and centuries. The terms of hour, day, month, year and century are all units of time measurements of a calender system.
    According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years.
    Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.
    Input

    The input consists of lines each containing a positive integer, which is the number of days that have elapsed since January 1, 2000 A.D. The last line contains an integer ?1, which should not be processed.
    You may assume that the resulting date won’t be after the year 9999.
    Output

    For each test case, output one line containing the date and the day of the week in the format of "YYYY-MM-DD DayOfWeek", where "DayOfWeek" must be one of "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Saturday".
    Sample Input

    1730
    1740
    1750
    1751
    -1
    Sample Output

    2004-09-26 Sunday
    2004-10-06 Wednesday
    2004-10-16 Saturday
    2004-10-17 Sunday


    #include <stdio.h>
    int isRunNian(int n)
    {
     if(n%400==0||(n%4==0&&n%100!=0))
     return 1;
     else
     return 0;
    }//是否为闰年
    int monthdate(int i,int m)
    {
     int date;
     if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
     date=31;
     if(i==4||i==6||i==9||i==11)
     date=30;
     if(i==2)
     {
      if(isRunNian(m))
      date=29;
      else
      date=28;
     }
     return date;
    }//这个月多少天
    int main()
    {
     int n;
     char week[][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
     while(scanf("%d",&n)&&n!=-1)
     {
      int i,j,k,t,m;
      i=2000;j=1;t=366;k=31;m=n;
      while(m/t>0)
      {
       i++;
       m-=t;
          if(isRunNian(i))
          t=366;
          else
          t=365;
      }//计算年份
      while(m/k>0)
      {
       j++;
       m-=k;
       k=monthdate(j,i);
      }//计算月份
      printf("%d-%02d-%02d ",i,j,m+1);
      printf("%s ",week[(n-1)%7]);
     }
     return 0;
    }

  • 相关阅读:
    代码高亮测试
    docker详解
    生成python项目的docker模板
    Windows下载Ubuntu的文件,用WinSCP软件(建议用MobeXterm),Ubuntu开启SSH连接
    分配堆内存的四种方式
    像素和rgb
    自由飞翔
    像素和分辨率的关系
    DOM事件阶段以及事件捕获与事件冒泡先后执行顺序
    有点甜 汪苏泷
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3227349.html
Copyright © 2011-2022 走看看