• What day is it


    Description

    Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?       
                  

    Input

    There are multiply cases.        One line is one case.        There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).       
                  

    Output

    Output one line.        if the date is illegal, you should output "illegal". Or, you should output what day it is.       
            

    Sample Input

    2007 11 17
                  

    Sample Output

    Saturday
     
     
    注意这题细节很多,我是从0001年01月01日为周一考虑的。
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <cstring>
     4 using namespace std;
     5 int a[]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
     6 int b[]={0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
     7 char c[8][11]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
     8 int panduan(int y)
     9 {
    10     if((y%4==0 && y%100!=0) || y%400==0)
    11         return 1;
    12     return 0;
    13 }
    14 int main()
    15 {
    16    int y, m, d, sum, i;
    17    while(cin>>y>>m>>d)
    18    {
    19       if(panduan(y))
    20       {
    21           if(d>b[m]||m==0||d==0)
    22             {
    23                 cout << "illegal" << endl;
    24                 continue;
    25             }
    26       }
    27       else
    28         {
    29             if(d>a[m]||m==0||d==0)
    30             {
    31                 cout << "illegal" << endl;
    32                 continue;
    33             }
    34         }
    35         sum=0;
    36         for (i=1; i<y; ++i)
    37             {
    38                if(panduan(i))
    39                 sum += 366;
    40                else
    41                 sum += 365;
    42 
    43             }
    44         for(int i = 0; i < m; ++i)
    45         {
    46             if(panduan(y))
    47                 sum += b[i];
    48             else
    49                 sum += a[i];
    50 
    51         }
    52         sum+=d;
    53         sum%=7;
    54         cout<< c[sum] << endl;
    55    }
    56    return 0;
    57 }
  • 相关阅读:
    0_ReviewML-1
    1_Convolution(卷积)
    0_overview
    遗传算法
    使用多线程下载文件思路
    大文件断点下载
    输出流
    大文件的下载
    XML解析
    文件下载
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4552499.html
Copyright © 2020-2023  润新知