首页 > 其他 > 详细

POJ - 2080 Calendar

时间:2014-05-10 09:26:54      阅读:395      评论:0      收藏:0      [点我收藏+]

题意:求2000.1.1(周六)过n天后,是哪年哪月哪日星期几

思路:看到过好多次了这种题,细心点模拟就是了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char w[7][10]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ,"Saturday"};  
int m[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 yd[2]={365,366};  
long long day;

int main(){
	int year,month,week;
	while (scanf("%lld", &day) != EOF && day!=-1){
		week = (day+6)%7;
		year = 2000;
		int flag = (year%4==0 && year%100!=0)||year%400==0;
		++day;
		while (day > yd[flag]){
			day -= yd[flag];
			year++;
			flag = (year%4==0 && year%100!=0)||year%400==0;
		}
		for (month = 1; day > m[flag][month]; month++)
			day -= m[flag][month];
		printf("%d-%02d-%02lld %s\n",year,month,day,w[week]);
	}
	return 0;
}



POJ - 2080 Calendar,布布扣,bubuko.com

POJ - 2080 Calendar

原文:http://blog.csdn.net/u011345136/article/details/24991005

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!