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

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;
}

POJ 2210 Metric Time【日期】相关推荐

  1. POJ 2210 Metric Time G++

    #include <iostream> #include <cstdio> using namespace std; int hs[13]={0,31,28,31,30,31, ...

  2. Bailian2723 不吉利日期(POJ NOI0113-02)【日期计算】

    问题链接:POJ NOI0113-02 不吉利日期. 原题出处:Bailian2723 不吉利日期. 总时间限制: 1000ms 内存限制: 65536kB 描述 在国外,每月的13号和每周的星期5都 ...

  3. POJ前面的题目算法思路【转】

    1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...

  4. POJ 超详细分类

    POJ 各题算法 1000    A+B Problem            送分题     49%    2005-5-7 1001    Exponentiation         高精度   ...

  5. 程序设计入门经典题解(百练篇)

    参考链接:PKU百练题解(Bailian) Bailian1017 装箱问题[贪心] - 海岛Blog - CSDN博客 POJ1088 Bailian1088 滑雪[DFS+记忆化搜索]_海岛Blo ...

  6. (精)【ACM刷题之路】POJ题目详细多角度分类及推荐题目

    POJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: ...

  7. poj题目详细分类及算法推荐题目

    DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  ...

  8. ACM POJ 题目分类(完整整理版本)

    DP: 1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题   ...

  9. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

最新文章

  1. vijos P1190繁忙的都市(Kruskal)(最小生成树)
  2. [ Luogu 3924 ] 康纳的线段树
  3. boost::callable_traits添加成员指针的测试程序
  4. Jzoj4764 Brothers
  5. python 伪造源ip_Swaks伪造邮件
  6. 【动态规划】区间dp: P3205 合唱队
  7. 190524每日一句
  8. spring boot 用dbcp2连接数据库出现(Access denied for user 'root'@'localhost' (using password: YES)) 异常
  9. matlab导出prn文件怎么打开,prn文件怎么打开?prn是什么意思?
  10. qq音乐linux版本下载地址,qq音乐linux版本下载
  11. 美化MyEclipse
  12. NutUI 京东小程序发布了!
  13. 医学信息化管理与建设
  14. 解决VS2016中Scanf运行错误
  15. python 爬取漫画《黑鹭尸体宅配便》
  16. 【转】软件安装错误2203(The error code is 2203)
  17. Android 听筒 扬声器 切换
  18. 实战 | UI 自动化测试框架设计与 PageObject 改造
  19. KPA EtherCAT主站协议栈基准
  20. 一句话木马 php asp,一句话木马源代码

热门文章

  1. python数据处理工具-Pandas笔记
  2. 凯撒密码,可输入任意长度字符串进行转换
  3. access团员人数公式_2015年3月全国二级ACCESS操作真题第1套
  4. 推荐系统论文:Personalized News Recommendation Based on ClickBehavior
  5. 《禅与摩托车维修艺术》读后感第一篇
  6. PCIe设备在一个系统中是如何发现与访问的
  7. 《python 程序设计》读书笔记
  8. 解决win7系统重启后ip丢失问题,即每次电脑重启都要重新设置ip地址,重启后ip地址没了
  9. 超微服务器安装Linux,超微服务器使用IPMI安装操作系统
  10. 几何语言点C是ab的中点,数学几何定理符号语言