POJ 2210 Metric Time "date"

Source: Internet
Author: User

The first call to a function, the result is timed out, and then the leap year to determine the array storage, it is over. It may be time-consuming to judge each time, and it will take a while to judge.

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 is then more stable, which meets the main goal of the party. 

The length of one day was the same as with the "classic" time. The day is divided to metric hours, each of which them into metric minutes, and each minute into metric seconds. Ten metric days form one metric week, metric weeks give one metric month, metric months is 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 is very difficult to the new time. PSOS chairman decided to solve these problems all at once. He plans to publish a freeware utility which would 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 is counted starting with zero, as usual. Metric days and Metric months start with one. There exist metric year zero. The metric seconds should is rounded to the nearest smaller integer value. Assume that 0:0:0 1.1.2000 classic time was equal to 0:0:0 1.1.0 Metric time. 

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

Input

At the first line there are 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 was the date in the Clas Sic form (usual in the most of European countries). The date is always valid, and <= year <= 50000.

Output

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

Sample Input

70:0:0 1.1.200010:10:10 1.3.20010:12:13 1.3.240023:59:59 31.12.20010:0:1 20.7.74780:20:20 21.7.747815:54:44 2.10.20749

Sample Output

0:0:0 1.1.04:23:72 26.5.00:8:48 58.2.1469:99:98 31.8.00:0:1 100.10.20000:14:12 1.1.20016:63:0 7.3.6848

Source

CTU FEE Local 1998

AC Code:

#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;elseleap[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", &AMP;HOUR,&AMP;C1,&AMP;MINUTE,&AMP;C2, &second,&c3,&day,&c4,&month,&c5,&year); int i,sum=0;for (i=2000;i<year;i++) {if ( Leap[i]) sum+=366;elsesum+=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;//Test instructions is saying that the time of day is the same, so 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)//Ask how many days this has been before {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;elsesum+=28;}} Sum+=day-1;return sum;}


Just called a function, it timed out, nothing

Timeout code:

#include <stdio.h>int isrunnian (int), 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", &AMP;HOUR,&AMP;C1,&AMP;MINUTE,&AMP;C2,&AMP;SECOND,&AMP;C3,&AMP;DAY,&AMP;C4 , &month,&c5,&year); int i,sum=0;for (i=2000;i<year;i++) {if (Isrunnian (i)) sum+=366;elsesum+=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;//Test instructions is saying that the time of day is the same, so 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;elsereturn 0;} int Dijitian (int year,int month,int Day)//Ask how many days this has gone {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;elsesum+=28;}} Sum+=day-1;return sum;}


POJ 2210 Metric Time "date"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.