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

POJ 2210 Metric Time【日期】

时间:2015-04-09 08:56:25      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

一开始调用一个函数,结果竟然超时了,后来将闰年判断换成数组存储,就过了。可能每一次都来判断一次就比较耗时,一次都判断完就省时间了。

 

Metric Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2615   Accepted: 811

Description

The Metric Time is one of the most important points of PSOS Election Programme. The Time can be much easier calculated in operating systems. These systems are then more stable, which meets the main goal of the Party. 

The length of one day is the same as with the "classic" time. The day is divided into 10 metric hours, each of them into 100 metric minutes, and each minute into 100 metric seconds. 10 metric days form one metric week, 10 metric weeks give one metric month, 10 metric months are called metric year. It is obvious this Metric Time is much better than the classic one. 

Some opponent parties often complain that the Metric Time has also some drawbacks. First of all, it would be very difficult to change to the new time. PSOS Chairman decided to solve these problems all at once. He plans to publish a freeware utility which will be able to convert between the time formats. Your goal is to write one half of this utility, the program which converts classic time to Metric Time. Metric hours, metric minutes, and metric seconds are counted starting with zero, as usual. Metric days and metric months start with one. There exist metric year zero. The metric seconds should be rounded to the nearest smaller integer value. Assume that 0:0:0 1.1.2000 classic time is equal to 0:0:0 1.1.0 Metric Time. 

Note that the classic year is leap, if it is an integer multiple of 4. The only exception are years divisible by 100 - they are leap only if they are an integer multiple of 400. For example, leap years are 1996, 2400, and 2000; leap years are not 1900, 2300, 2002. 

Input

At the first line there is a positive integer N stating the number of assignments to follow. Each assignment consists of exactly one line in the form "hour:minute:second day.month.year" which is the date in the classic form (usual in most of European countries). The date is always valid, 2000 <= year <= 50000.

Output

The program must print exactly one line for each assignment. The line should have the form "mhour:mmin:msec mday.mmonth.myear" which is the Metric Time equal to the specified classic time.

Sample Input

7
0:0:0 1.1.2000
10:10:10 1.3.2001
0:12:13 1.3.2400
23:59:59 31.12.2001
0:0:1 20.7.7478
0:20:20 21.7.7478
15:54:44 2.10.20749

Sample Output

0:0:0 1.1.0
4:23:72 26.5.0
0:8:48 58.2.146
9:99:98 31.8.0
0:0:1 100.10.2000
0:14:12 1.1.2001
6:63:0 7.3.6848

Source

 

 

AC代码:

#include<stdio.h>
#include<string.h>
int leap[50010];
//int isRunNian(int year);
int DiJiTian(int year,int month,int day);

void is_leap()
{
	int i,j;
	memset(leap,0,sizeof(leap));
	for(i=2000;i<=50000;i++)
	{
		if(i%400==0||(i%4==0&&i%100!=0))
			leap[i]=1;
		else
			leap[i]=0;
	}
}

int main()
{
	int hour,minute,second,day,month,year;
	int mhour,mmin,msec,mday,mmonth,myear;
	char c1,c2,c3,c4,c5;
	int s;
	is_leap();
	scanf("%d",&s);
	while(s--)
	{
		scanf("%d%c%d%c%d%c%d%c%d%c%d",&hour,&c1,&minute,&c2,&second,&c3,&day,&c4,&month,&c5,&year);
		int i,sum=0;
		for(i=2000;i<year;i++)
		{
			if(leap[i])
				sum+=366;
			else
				sum+=365;
		}
		sum += DiJiTian(year,month,day);
		myear=sum/1000;		sum%=1000;
		mmonth=sum/100+1;	sum%=100;
		mday=sum+1;
		
		sum=(hour*3600+minute*60+second)*125/108;// 题意是说一天的时间是一样的 ,所以100000/(24*3600)=125/108 
		mhour=sum/10000;	sum%=10000;
		mmin=sum/100;	sum%=100;
		msec=sum;
		printf("%d%c%d%c%d%c%d%c%d%c%d\n",mhour,c1,mmin,c2,msec,c3,mday,c4,mmonth,c5,myear);
	}
	return 0;
} 


//int isRunNian(int year)
//{
//	if(year%400==0||(year%4==0&&year%100!=0))
//		return 1;
//	else
//		return 0;
//}

int DiJiTian(int year,int month,int day)//求当前这已经过了多少天
{
	int i,sum=0;
	for(i=1;i<month;i++)
	{
		if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
			sum+=31;
		else if(i==4||i==6||i==9||i==11)
			sum+=30;
		else if(i==2)
		{
			if(leap[year])
				sum+=29;
			else
				sum+=28;
		}
	}
	sum+=day-1;
	return sum;
}


 

 

只是调用了一个函数,就超时,没啥

超时代码:

#include<stdio.h>
int isRunNian(int year);
int DiJiTian(int year,int month,int day);
int main()
{
	int hour,minute,second,day,month,year;
	int mhour,mmin,msec,mday,mmonth,myear;
	char c1,c2,c3,c4,c5;
	int s;
	scanf("%d",&s);
	while(s--)
	{
		scanf("%d%c%d%c%d%c%d%c%d%c%d",&hour,&c1,&minute,&c2,&second,&c3,&day,&c4,&month,&c5,&year);
		int i,sum=0;
		for(i=2000;i<year;i++)
		{
			if(isRunNian(i))
				sum+=366;
			else
				sum+=365;
		}
		sum += DiJiTian(year,month,day);
		myear=sum/1000;		sum%=1000;
		mmonth=sum/100+1;	sum%=100;
		mday=sum+1;
		
		sum=(hour*3600+minute*60+second)*125/108;// 题意是说一天的时间是一样的 ,所以100000/(24*3600)=125/108 
		mhour=sum/10000;	sum%=10000;
		mmin=sum/100;	sum%=100;
		msec=sum;
		printf("%d%c%d%c%d%c%d%c%d%c%d\n",mhour,c1,mmin,c2,msec,c3,mday,c4,mmonth,c5,myear);
	}
	return 0;
} 


int isRunNian(int year)
{
	if(year%400==0||(year%4==0&&year%100!=0))
		return 1;
	else
		return 0;
}

int DiJiTian(int year,int month,int day)//求当前这已经过了多少天
{
	int i,sum=0;
	for(i=1;i<month;i++)
	{
		if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
			sum+=31;
		else if(i==4||i==6||i==9||i==11)
			sum+=30;
		else if(i==2)
		{
			if(isRunNian(year))
				sum+=29;
			else
				sum+=28;
		}
	}
	sum+=day-1;
	return sum;
}


 

 

 

 

 

 

 

 

 

 

POJ 2210 Metric Time【日期】

标签:

原文地址:http://blog.csdn.net/qq_16767427/article/details/44947431

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