Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

牛人帮忙

Posted by rain0629 at 2006-03-03 21:24:52 on Problem 2080
我也是对着万年历看了好久
不知所错何处

#include<iostream>
#include<iomanip>
using namespace std;

const int NORM = 365, LEAP = 366;
struct SDate{
    int iyear, imon, iday;
	char *cpweek;
};
void main()
{
	SDate Ddate;
	int idays, itemp;
	bool isLeap;
	int iamon[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}};
	char *cpaweek[7] = {"Saturday", "Sunday", "Monday","Tuesday", "Wednesday", "Thursday", "Friday"};

	scanf("%d", &idays);
	
	while(idays != -1){
		Ddate.iyear = 2000;
		isLeap = true;

        itemp = idays + 1;
		
		while(1){                                                                    //deal with year
			if(itemp > LEAP){
				itemp -= LEAP;  
		    	Ddate.iyear++; 
				isLeap = false;
			}
			else break;
	
			for(int i = 0; i < 3 && itemp > NORM; i ++) {
				itemp -= NORM;  
				Ddate.iyear++;
			}
			if(i == 3) isLeap = true;
			else break;
		}

		for(Ddate.imon = 1; itemp > iamon[isLeap][Ddate.imon]; Ddate.imon++) 
			itemp -= iamon[isLeap][Ddate.imon];

		Ddate.iday = itemp; 
        Ddate.cpweek = cpaweek[idays % 7];
	    
		printf("%d-%02d-%02d %s", Ddate.iyear, Ddate.imon , Ddate.iday, Ddate.cpweek);

		scanf("%d", &idays);
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator