What day is it hdu2133(終於AC)

來源:互聯網
上載者:User

//#include<stdio.h>
#include<iostream>//2348036 2010-04-16 14:16:54 Accepted 2133 15MS 232K 1474 B C++ 悔惜晟
#include<cstdio>
using namespace std;

char s[7][11]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int leap(int n)
{
    if((n % 4 == 0 && n % 100 != 0) || n % 400 == 0)
        return 1;
    else
 return 0;
}
int main()
{
    int year1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};// 平年
    int year2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; // 潤年
    int year,month,date,i,flag,tem;
    while(scanf("%d %d %d",&year,&month,&date) ==3)
    {
     if(month<1 || year>9999 || year<1 || month>12 || date <= 0 ) // data < 0 的情況沒有考慮到,錯了好多篇,以為是沒有錯誤的了
 {         // 看了論壇我才知道問題出現在這裡
  printf("illegal/n");
  continue;
 }

        if(leap(year)) // 如果是潤年
        {
            if(date > year2[month])
     {
      printf("illegal/n");
      continue;
     }
        }
        else  // 如果是平年
        {
            if(date > year1[month])
     {
      printf("illegal/n");
      continue;
     }
        }

        flag=0;   
        for( i = 2; i <= year; i++)
        {
            if(leap(i-1))
      flag += 366;
            else
      flag += 365;
        }
        if( leap(year) ) // 如果是潤年
        {
            for( i = 1; i < month; i++)
   flag += year2[i];
        }
        else // 如果是平年
        {
            for(i = 1;i < month; i++)
  flag += year1[i];
        }
        flag += date;
        tem = flag % 7;
        printf("%s/n",s[tem]);
    }
    return 0;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.