zoukankan      html  css  js  c++  java
  • 【HDOJ】2133 What day is it

    需要注意数据有效性。

     1 #include <stdio.h>
     2 
     3 #define isLeapYear(y) (y%4==0&&y%100!=0)||(y%400==0)
     4 
     5 int nums[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31}};
     6 char buf[7][20] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
     7 
     8 int main() {
     9     int i, j, year, month, day, total;
    10 
    11     while (scanf("%d %d %d", &year, &month, &day) != EOF) {
    12         total = day;
    13         j = isLeapYear(year);
    14         if (month==0 || day==0) {
    15             printf("illegal
    ");
    16             continue;
    17         }
    18         for (i=1; i<month; ++i)
    19             total += nums[j][i];
    20         if (month == 2) {
    21             if (!j && day>28) {
    22                 printf("illegal
    ");
    23                 continue;
    24             }
    25             if (j && day>29) {
    26                 printf("illegal
    ");
    27                 continue;
    28             }
    29         }
    30         if ((month==4||month==6||month==9||month==11) && day>30) {
    31             printf("illegal
    ");
    32             continue;
    33         }
    34         for (i=1; i<year; ++i) {
    35             if (isLeapYear(i))
    36                 total += 366;
    37             else
    38                 total += 365;
    39         }
    40         i = total % 7;
    41         printf("%s
    ", buf[i]);
    42     }
    43 
    44     return 0;
    45 }
  • 相关阅读:
    提问回顾与个人总结
    软工结对作业
    软件工程第一次阅读作业
    软件工程第0次作业
    oo第四次博客总结
    第三次博客总结
    第二次博客作业
    OO第一次总结博客
    软工第二次作业
    软工第一次作业
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3687525.html
Copyright © 2011-2022 走看看