描述
-
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.
输入
-
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.
输出
-
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.
样例输入
-
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
样例输出
-
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
来源
-
CTU FEE Local 1998
-
-
可以通过模拟来一年一年一天天的爬过去,但是年份较大时比较慢,虽然公式计算比较恶心,但至少效率较高
-
-
时分秒和年月日可以分开计算,这是这道题简便的地方
-
-
问题的关键在于过去的年份中有多少年是闰年:
-
闰年数= 4倍数年的个数-100倍数年的个数+400倍数年的个数
-
这个公式中要记住2000年也是闰年
-
-
根据总天数逐步统计出新历的年月日,注意整千日,整百日的处理。
-
-
#include<iostream>
#include<stdio.h>
using namespace std;
int month_day_noleap[13] = { 0,0,31,59,90,120,151,181,212,243,273,304,334 };
int month_day_leap[13] = { 0,0,31,60,91,121,152,182,213,244,274,305,335 };
bool isleap(int y) {
if (y % 4 == 0) {
if (y % 100 == 0) {
if(y % 400 == 0)
return true;
return false;
}
return true;
}
else return false;
}
int main() {
int N = 0;
cin >> N;
while (N--) {
double ch, cmin, cs;
int cy, cmon, cd;
int mh, mmin, ms, my, mmon, md;
double day_s;
int totalday;
int leapnum = 0;
scanf("%lf:%lf:%lf %d.%d.%d", &ch, &cmin, &cs, &cd, &cmon, &cy);
day_s = (ch * 3600 + cmin * 60 + cs)*100000/86400;
mh = day_s / 10000;
day_s = day_s - mh * 10000;
mmin = day_s / 100;
day_s = day_s - mmin * 100;
ms = day_s;
//-------------------
totalday = (cy - 2000) * 365;
if (isleap(cy)) {
totalday += month_day_leap[cmon];
}
else {
totalday += month_day_noleap[cmon];
}
totalday += cd;
if (cy > 2000)
leapnum = (cy - 2001) / 4 + 1 - ((cy - 2001) / 100 + 1) + (cy - 2001) / 400 + 1;
else
leapnum = 0;
totalday += leapnum;
my = (totalday - 1) / 1000;
totalday = totalday % 1000;
if (totalday != 0) {
mmon = (totalday - 1) / 100 + 1;
totalday = totalday % 100;
if (totalday == 0) {
md = 100;
}else
md = totalday;
}
else {
mmon = 10;
md = 100;
}
printf("%d:%d:%d %d.%d.%d\n",mh,mmin,ms,md,mmon,my);
}
return 0;
}