zoukankan      html  css  js  c++  java
  • HDUOJ Calendar

    Calendar
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 9036   Accepted: 3390

    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

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 int shu1[13]={31,28,31,30,31,30,31,31,30,31,30,32};
     4 int shu2[12]={31,29,31,30,31,30,31,31,30,31,30,32};
     5 char str[8][15]={"Monday","Tuesday","Wednesday" ,"Thursday","Friday","Saturday","Sunday"};
     6 int leap(int year)
     7 {
     8     
     9     if((year%400==0)||((year%4==0)&&(year%100!=0)))
    10     return 1;
    11     return 0;
    12 }
    13 int main()
    14 {
    15     int n,i,mon,year,yearday,k,day;
    16     while(scanf("%d",&n)&&(n!=-1))
    17     {   
    18         k=(n+5)%7;
    19         n=n+1;
    20        year=2000;mon=1;
    21        yearday=leap(year)?366:365;
    22        while(n>yearday)
    23        {
    24          n-=yearday;
    25          year++;
    26          yearday=leap(year)?366:365;
    27         //printf("n==%d",n);//
    28        }
    29        if(leap(year))
    30        {  i=0;
    31          while(n>shu2[i])
    32           {//printf("mon=%d",mon);//
    33              mon++;
    34              
    35              n-=shu2[i];
    36              i++;
    37             // printf("n=%d,i=%d\n",n,i);
    38           }
    39        }
    40        else 
    41        {  i=0;
    42          while(n>shu1[i])
    43           {
    44              mon++;
    45              n-=shu1[i];
    46              i++;
    47           }
    48        }
    49        
    50        day=n;
    51        printf("%4d-%02d-%02d %s\n",year,mon,day,str[k]);
    52     }
    53 return 0;
    54 }
    55       
  • 相关阅读:
    macos删除本地快照
    mount error(13): Permission denied Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) RHEL 7 配置samba(smb)文件共享报错
    增加samba用户提示Failed to add entry for user
    Linux中变量 $#, $@, $0, $1,$ 2, $*,$$,$?的含义
    虚拟主机是设置在httpd-vhosts.conf还是vhosts.conf还是httpd.conf
    linux 中useradd -s /sbin/nologin和/bin/false的区别
    Linux系统 smbpasswd 命令的用法?
    linux 下/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的区别
    linux防火墙
    etc/selinux/config与etc/sysconfig/selinux区别
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_2012_07_2600.html
Copyright © 2011-2022 走看看