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 loneknight at 2005-03-16 12:10:15 on Problem 2210
In Reply To:这都会wa!!没天理了! Posted by:ferrettemp at 2005-03-16 09:09:25
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int	days[][12] =
{
	{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, },
	{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, },
};

int is_leap(int year);

int
main(int argc, char *argv[])
{
	int	n;
	cin >> n;
	
	while (--n >= 0)
	{
		int	hour, min, secs;
		int	day, month, year;
		char	tmp;
		
		scanf("%d:%d:%d %d.%d.%d", &hour, &min, &secs, &day, &month, &year);
		
		int	total = 0;
		total += 365*(year - 2000) + (year - 2000)/4 - (year - 2000)/100 + (year - 2000)/400;
		total += !is_leap(year);
		
		for (int i = 0; i < month-1; ++i)
			total += days[is_leap(year)][i];
		
		total += day - 1;
		
		day = total % 100 + 1;
		month = total/100 % 10 + 1;
		year = total/1000;
		
		total = 0;
		total += hour * 60 * 60;
		total += min * 60;
		total += secs;
		
		total *= 125;
		total = total/108;
		
		secs = total % 100;
		min = total/100 % 100;
		hour = total / 10000;
		
		printf("%d:%d:%d %d.%d.%d\n", hour, min, secs, day, month, year);
	}
	
	return 0;
}

int
is_leap(int year)
{
	return (year%4 == 0) && year%100 || (year%400 == 0);
}

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