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

POJ2210 Metric Time【日期计算】

时间:2018-12-30 20:17:41      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:rman   语言   format   scan   tin   number   draw   exactly   mit   

Metric Time
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2810 Accepted: 889
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

问题链接POJ2210 Metric Time
问题简述:(略)
问题分析
????这个问题逻辑上并不复杂,是一个有关日期计算的问题,按照题意进行计算即可。
程序说明
????如果采用模拟计算,似乎会出现TLE。推导出计算公式直接计算的话则AC。有点诡异啊!!!
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* POJ2210 Metric Time */

#include <stdio.h>

int mdays[] = {
      0
    , 31
    , 28 + 31
    , 31 + 28 + 31
    , 30 + 31 + 28 + 31
    , 31 + 30 + 31 + 28 + 31
    , 30 + 31 + 30 + 31 + 28 + 31
    , 31 + 30 + 31 + 30 + 31 + 28 + 31
    , 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31
    , 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31
    , 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31
    , 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31
    , 31 +  30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31
};

int leapyear(int year, int mon)
{
    return (mon > 2 && (((year%4==0) && (year%100!=0)) || (year%400==0))) ? 1 : 0;
}

int main()
{
    int n;
    scanf("%d", &n);
    while(n--) {
        int h, min, s, d, mon, y;
        scanf("%d:%d:%d %d.%d.%d", &h, &min, &s, &d, &mon, &y);
        long long sumsecs = (h * 3600+ min * 60+ s) * 100000LL / (3600 * 24);
        int sumdays = 0;
        if (y !=2000)
            sumdays = 366 + 365 * (y - 1 - 2000) + (y - 1 - 2000) /4- (y -1 - 2000) / 100+ (y -1-2000) / 400;
        sumdays += mdays[mon - 1] + leapyear(y, mon);
        sumdays += d - 1;
        printf("%lld:%lld:%lld", sumsecs /10000, sumsecs %10000/100, sumsecs %100);
        printf(" %d.%d.%d\n", sumdays %100+1, sumdays %1000/100+1, sumdays /1000);
    }

    return 0;
}

TLE的C语言程序如下:

/* POJ2210 Metric Time */

#include <stdio.h>

int mdays[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int leapyear(int year)
{
    return ( ((year%4==0) && (year%100!=0)) || (year%400==0) ) ? 1 : 0;
}

int main(void)
{
    int n, h, m, s, day, mon, year,  mhor, mmin, msec, mday, mmon, myear;
    scanf("%d", &n);
    while(n--) {
        scanf("%d:%d:%d %d.%d.%d", &h, &m, &s, &day, &mon, &year);
        long long secs, days = 0, i;
        secs = s + m * 60 + h * 3600;
        for(i = 2000; i < year; i++)
            days += 365 + leapyear(i);
        for(i = 1; i < mon; i++)
            days += mdays[i];
        if(mon > 2)
            days += leapyear(year);
        days += day - 1;

        myear = days / 1000;
        days %= 1000;
        mmon = days / 100 + 1;
        days %=100;
        mday = days + 1;

        secs = secs * 125 / 108;
        mhor = secs / 10000;
        secs %= 10000;
        mmin = secs / 100;
        msec = secs % 100;

        printf("%d:%d:%d %d.%d.%d\n", mhor, mmin, msec, mday, mmon, myear);
    }

    return 0;
}

POJ2210 Metric Time【日期计算】

标签:rman   语言   format   scan   tin   number   draw   exactly   mit   

原文地址:https://www.cnblogs.com/tigerisland45/p/10200238.html

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