码迷,mamicode.com
首页 > 其他好文 > 详细

POJ - 2080 Calendar

时间:2014-05-10 09:28:33      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   int   

题意:求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

标签:style   blog   class   code   c   int   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!