标签:代码 clu title amp tar view 描述 解决 class
1730 1740 1750 1751 -1
2004-09-26 Sunday 2004-10-06 Wednesday 2004-10-16 Saturday 2004-10-17 Sunday
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; int days_of_year[2] = {365,366}; int days_of_month[24] = {31,28,31,30,31,30,31,31,30,31,30,31,/**/31,29,31,30,31,30,31,31,30,31,30,31}; char days_of_week[7][20] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ,"Saturday"}; int main() { int day; int start_year,start_month,start_day,start_week; int is_leap_year; while(scanf("%d",&day),day!=-1) { start_year = 2000; start_month = 1; start_day = 1; start_week = 6; start_week = (start_week + day) % 7; //判断是否闰年 if(start_year % 4 == 0 && !(start_year % 100 == 0 && start_year % 400 != 0)) { is_leap_year = 1; } else { is_leap_year = 0; } while(day >= days_of_year[is_leap_year]) { start_year ++; day -= days_of_year[is_leap_year]; //判断是否闰年 if(start_year % 4 == 0 && !(start_year % 100 == 0 && start_year % 400 != 0)) { is_leap_year = 1; } else { is_leap_year = 0; } } while(day >= days_of_month[is_leap_year*12 + start_month - 1]) { day -= days_of_month[is_leap_year*12 + start_month - 1]; start_month ++; } start_day += day; printf("%d-%02d-%02d %s\n",start_year,start_month,start_day,days_of_week[start_week]); } return 0; }
代码二:
#include <stdio.h> int judgeyear(int); int main() { long days; int i,j; int mon[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}}; int year[2]={365,366}; char day[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"}; int dow; while(scanf("%ld",&days),days!=-1) { dow=days%7; days+=1; for(i=2000 ; (days-year[judgeyear(i)])>0 ; i++) days-=year[judgeyear(i)]; int t=judgeyear(i); for(j=1 ; (days-mon[t][j])>0 ; j++) days-=mon[t][j]; printf("%d-%02d-%02ld %s\n",i,j,days,day[dow]); } return 0; } int judgeyear(int a) { if(a%4!=0 || (a%100 == 0 && a%400 !=0)) return 0; else return 1; }
标签:代码 clu title amp tar view 描述 解决 class
原文地址:http://www.cnblogs.com/gcter/p/7372581.html