有一种特殊的日历法,它的一天和我们现在用的日历法的一天是一样长的。
它每天有10个小时,每个小时有100分钟,每分钟有100秒。
10天算一周,10周算一个月,10个月算一年。
现在要你编写一个程序,将我们常用的日历法的日期转换成这种特殊的日历表示法。
这种日历法的时、分、秒是从0开始计数的。
日、月从1开始计数,年从0开始计数。
秒数为整数。
假设 0:0:0 1.1.2000 等同于特殊日历法的 0:0:0 1.1.0。
输入
第一行是一个正整数 N ,表明下面有 N 组输入。每组输入有一行,格式如下:hour:minute:second day.month.year
表示常规的日期。日期总是合法的。2000 <= year <= 50000。
输出
每组输入要求输出一行。格式如下:
mhour:mmin:msec mday.mmonth.myear
是输入日期的特殊日历表示方法。
样例输入
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
代码:
#include<iostream>
#include<string>
using namespace std;
int years[] = { 366,365 };
int days[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int daysr[] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
int isrun(int n) {
if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0)
return 0;
return 1;
}
int main() {
int n; cin >> n;
while (n--) {
string time, date;
cin >> time >> date;
int hour = stoi(time.substr(0, time.find(":")));
time = time.substr(time.find(":") + 1);
int minute = stoi(time.substr(0, time.find(":")));
time = time.substr(time.find(":") + 1);
int second = stoi(time);
int day = stoi(date.substr(0, date.find(".")));
date = date.substr(date.find(".") + 1);
int month = stoi(date.substr(0, date.find(".")));
date = date.substr(date.find(".") + 1);
int year = stoi(date);
int thedays = 0;
for (int i = 2000; i < year; i++) {
thedays += years[isrun(i)];
}
if (isrun(year) == 0)
for (int i = 1; i < month; i++)
thedays += daysr[i];
else
for (int i = 1; i < month; i++)
thedays += days[i];
thedays += (day-1);
year = thedays / 1000;
month = thedays % 1000 / 100 + 1;
day = thedays % 1000 % 100 + 1;
int thesecond = (hour * 3600 + minute * 60 + second)*125/108;
hour = thesecond/ 10000;
minute = thesecond % 10000 / 100;
second = thesecond % 10000 % 100;
cout << hour << ":" << minute << ":" << second << " " << day << "." << month << "." << year << endl;
}
system("pause");
}