POJ 2210 Metric Time【日期】

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

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

CTU FEE Local 1998

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;
}
时间: 2024-11-08 16:52:10

POJ 2210 Metric Time【日期】的相关文章

POJ 2964:日历问题 日期转换+闰年月份可放在一个month[2][12]数组里

2964:日历问题 查看 提交 统计 提示 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 在我们现在使用的日历中, 闰年被定义为能被4整除的年份,但是能被100整除而不能被400整除的年是例外,它们不是闰年.例如:1700, 1800, 1900 和 2100 不是闰年,而 1600, 2000 和 2400是闰年. 给定从公元2000年1月1日开始逝去的天数,你的任务是给出这一天是哪年哪月哪日星期几. 输入 输入包含若干行,每行包含一个正整数,表示从2000年1月1日开始

poj 3751 时间日期格式转换

题目链接:http://poj.org/problem?id=3751 题目大意:按照要求的格式将输入的时间日期进行转化. 1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 int main () 5 { 6 int t; 7 cin>>t; 8 while (t--) 9 { 10 int y,m,d,xs,fz,ms; 11 char ch1,ch2,ch3,ch4,ch5; 12

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348

poj 1006:Biorhythms(水题,经典题,中国剩余定理)

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical,

POJ C程序设计进阶 编程题#4:Tomorrow never knows?

来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 甲壳虫的<A day in the life>和<Tomorrow never knows>脍炙人口,如果告诉你a day in the life,真的会是tomorrow never knows?相信学了计概之后这个不会是难题,现在就来实现吧. 读入一个格式为yyyy-mm-dd的日期(即年-月-日),输出这个

POJ 3715:计算工作天数

代码: import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { // 获得员工数据 ArrayList<Staff> staffs = getStaffs(); // 计算相隔天数 staffs = calStaffWorkingDays(staffs); // 打印 printSortStaffs(staffs); }

poj 1008:Maya Calendar(模拟题,玛雅日历转换)

Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, profes

转载----POJ 1006 中国剩余定理

本文为转载,源地址:   http://blog.csdn.net/dongfengkuayue/article/details/6461298 POJ 1006   Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 78980   Accepted: 23740 Description Some people believe that there are three cycles in a perso