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;
    }

  • 相关阅读:
    设计模式---行为变化模式之命令模式(Command)
    设计模式---数据结构模式之职责链模式(Chain of Responsibility)
    设计模式---数据结构模式之迭代器模式(Iterate)
    WinCE全屏手写输入法
    .net下所有DLL(API)查询,转换C#代码
    在线cron表达式生成器
    完全卸载vs2013、vs2015的方法
    java微信 客服接口-发消息 中文乱码
    【路由达人】简单两步搞定小米路由新增功能-DDNS(解析域名地址转向在线工具)
    微信公众平台开发入门教程
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3227349.html
Copyright © 2011-2022 走看看