What day is it
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4261 Accepted Submission(s):
1252
Problem 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).
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.
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
Author
LGX
Source
//蔡勒公式坑 !
1 #include <stdio.h> 2 char str[20][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"} ; 3 int num[13] = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} ; //这边坑! 4 int shu[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} ; 5 6 int judge(int year) 7 { 8 if(year%4 == 0 && year%100!=0 || year%400 == 0) 9 return 1 ; 10 else 11 return 0; 12 } 13 14 int main() 15 { 16 int year, month, day, p ; 17 while(~scanf("%d %d %d",&year, &month, &day)) 18 { 19 int t = judge(year) ; 20 if(t == 0) //这边坑! 21 { 22 23 if(day > num[month] || month == 0 || day == 0) 24 { 25 printf("illegal ") ; 26 continue ; 27 } 28 } 29 else //这边坑; 30 { 31 //num[2] += 1 ; 32 if(day > shu[month] || month == 0 || day == 0) 33 { 34 printf("illegal ") ; 35 continue ; 36 } 37 } 38 39 int i, sum=0 ; 40 for(i=1; i<year; i++) 41 { 42 if(judge(i) == 1) 43 sum += 366 ; 44 else 45 sum += 365 ; 46 sum=sum%7 ; 47 } 48 49 sum += day ; 50 for(i=1; i<month; i++) 51 { 52 if(t == 1) 53 sum+= shu[i] ; 54 else 55 sum+=num[i] ; 56 sum = sum % 7 ; 57 } 58 sum = sum%7 ; 59 printf("%s " ,str[sum]) ; 60 } 61 return 0 ; 62 }
//考前来一发: